Reputation: 302
I need to print sheets (X & Y) on two different printers (PrinterX & Printer Y).
Dim PrinterX as string
PrinterX=activeworkbook.Worksheets("Printers").Range("B1).value
Activerprinter = PrinterX
ActiveWorkbook.Worksheets("X").Printout
Dim PrinterY as string
PrinterY = Activeworkbook.Worksheets("Printers").Range("B2).value
Activerprinter = PrinterY
ActiveWorkbook.Worksheets("Y").Printout
It prints both on the same first printer PrinterX.
I am trying to print X on PrinterX and Y on PrinterY
application.activeprinter
gives error.
Upvotes: 0
Views: 646
Reputation: 29421
you could use a loop not to repeat same code twice;
Sub main()
Dim iCell As Long
With Worksheets("Printers").Range("B1:B2") '<--| reference range with printers
For iCell = 1 To .Count '<--|loop through it
ActivePrinter = .Cells(iCell, 1).Value '<--| set activeprinter to curent cell value
Worksheets(Array("X", "Y")(iCell - 1)).PrintOut '<--| define array with corresponding wanted sheets names and printout current one
Next iCell
End With
End Sub
Upvotes: 0
Reputation: 33682
Make sure your "Printers" worksheet has 2 different printers setup in Range("B1")
, and Range("B2")
.
Code
Option Explicit
Sub PrinteronDifferentPrinters()
Dim PrinterX As String
Dim PrinterY As String
PrinterX = ActiveWorkbook.Worksheets("Printers").Range("B1").Value
Activerprinter = PrinterX
ActiveWorkbook.Worksheets("X").PrintOut
PrinterY = ActiveWorkbook.Worksheets("Printers").Range("B2").Value
Activerprinter = PrinterY
ActiveWorkbook.Worksheets("Y").PrintOut
End Sub
Upvotes: 1