I've scoured the internet but can't find an exact solution for this...I need to be able to set the color and duplex settings for printing from within my VBA code.
My intent is to use a VBA userform button to format and then print a table from my workbook. My abbreviated code is:
Application.PrintCommunication = False
With ws.PageSetup
.PrintArea = first & ":" & last
.PrintTitleRows = "$1:$1"
.LeftHeader = "&9&D &T"
.CenterHeader = "&A"
.RightHeader = "&9Page &P of &N"
.Orientation = xlLandscape
.PaperSize = xlPaper11x17
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
End With
Application.PrintCommunication = True
ws.PrintOut Preview:=True, ActivePrinter:="BODHPM750"
This formats the page and opens the preview window fine, but it defaults to black-and-white one-sided printing (per the office's printer settings) unless I've manually changed it since opening the workbook. These settings are associated with the printer, not the workbook, so I can't change them through ws.PageSetup or within the preview window.
EDIT: I also realized that the ActivePrinter definition isn't working. The print preview is opening for the default printer set on my computer, which is a different one from the one I'm trying to call in my ws.PrintOut command.
Is there a way for me to set this to print in color and duplex within this button press? I found information on using a Printer object within Access and other Office programs, but there doesn't seem to be one for Excel.
For reference - I'm using VBA in Excel 2016 and the printer I'm trying to use is an HP Color LaserJet M750 PCL 6 on an office server, if that's relevant.
UPDATE: Color issue resolved.