VBA printing publisher document (1 Viewer)

wackywoo105

Registered User.
Local time
Today, 12:14
Joined
Mar 14, 2014
Messages
203
I need help printing a publisher document created in Access VBA:

Code:
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:

Code:
 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.

Code:
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?
 

June7

AWF VIP
Local time
Today, 11:14
Joined
Mar 9, 2014
Messages
5,470
Example from my db which is used to print a report and make sure output is not duplex. You could try acPRDPDuplex but not sure how this could be adapated for Publisher document manipulation.
Code:
            If Application.Printer.DeviceName Like "*Konica*" Then
                Reports("SampleLabels").Printer.Duplex = acPRDPSimplex
                DoCmd.PrintOut
                DoCmd.Close acReport, "SampleLabels", acSaveNo
            End If
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:14
Joined
May 7, 2009
Messages
19,237
the Object is a Microsoft Publisher, not an access report.
 

wackywoo105

Registered User.
Local time
Today, 12:14
Joined
Mar 14, 2014
Messages
203
Thanks. As above I'm ok with access reports, I would just like to create a publisher doc, print it and then dispose of it. The problem with saving it first is sometimes different users cannot overwrite the previous version causing issues.

I've searched high and low but cannot find any example code, or anything that comes close that I could modify.

Even still having a duplicate printer setup with required settings and using
Code:
docpub.PrintOutEx
would be ok but I don't know how to make it use a specific printer. I think it just uses default printer. I guess I could run command line code to change the default printer, use it and then change it back again. hmm....
 
Last edited:

June7

AWF VIP
Local time
Today, 11:14
Joined
Mar 9, 2014
Messages
5,470
I knew it was Publisher document. I did state no idea if code could be adapted.

Yes, VBA can change default printer. I've also done that. Fairly common topic.

Code:
Private Sub btnPrint_Click()
'print to the color printer

Dim strDefaultPrinter As String

'load the current default printer into the variable strDefaultPrinter
strDefaultPrinter = Application.Printer.DeviceName

'switch to Konica printer for color printout
Set Application.Printer = Application.Printers("\\DotAtuPs01\DOT-PR-Atu Mat Konica 652 PCL")
'try to set printer for color - doesn't work, also tried API coding and that didn't work either
''Application.Printer.ColorMode = acPRCMColor
''Forms("ConcreteMixTools").Printer.ColorMode = acPRCMColor

Me.Detail.BackColor = vbWhite
DoCmd.PrintOut

'change the printer back to the default printer
Set Application.Printer = Application.Printers(strDefaultPrinter)

End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom