PDA

View Full Version : VBA printing publisher document



Agent Smith
01-14-2021, 11:34 AM
I need help printing a publisher document created in Access VBA:



Dim DocPub As Publisher.Document, appPub As New Publisher.Application, ShpTB As Publisher.Shape
Set DocPub = appPub.NewDocument
DocPub.Pages.Add count:=1, After:=1

*/ Create 2 page document /*



I want to print the document duplex and if possible choose the paper tray and printer.

I have some code that queries the available and active printer:



Dim pubInstalledPrinters As Publisher.InstalledPrinters
Dim pubPrinter As Publisher.Printer
'Set pubApplication = ThisDocument.Application
Set pubInstalledPrinters = appPub.InstalledPrinters
For Each pubPrinter In pubInstalledPrinters
Debug.Print pubPrinter.PrinterName
If pubPrinter.IsActivePrinter Then
Debug.Print "This is the active printer"
Debug.Print "Paper size is ", pubPrinter.PaperSize
Debug.Print "Paper orientation is ", pubPrinter.PaperOrientation
Debug.Print "Paper source is ", pubPrinter.PaperSource
Debug.Print "Duplex is ", pubPrinter.IsDuplex
End If
Next


But I cannot figure out how to manipulate printer settings and print duplex.


docpub.PrintOutEx

The above prints, but on 2 separate pages, even though the earlier code returns true for duplex. I'm assuming this is just showing the printer is duplex capable rather than set for duplex.

I have a workaround where I save the document and use command line to print using a pre configured duplicate printer, but would rather just print without this faff.

Can anyone help with how to print without having to save and selecting printer, tray and duplex?