suppress "print to file" dialog (Word 2000)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15615
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

suppress "print to file" dialog (Word 2000)

Post by ChrisGreaves »

I have experimented with both "PrimoPDF" and with "PDFill PDF&Image Writer" (thanks TomyRush and recorded a macro:

Code: Select all

Sub test()
    Dim strActivePrinter As String
    strActivePrinter = ActivePrinter
'    ActivePrinter = "PrimoPDF"
    ActivePrinter = "PDFill PDF&Image Writer"
    Dim strFileName As String
    strFileName = Format(Now(), "hhmmss")
    Application.PrintOut FileName:=ThisDocument.FullName, Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
        PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
    ActivePrinter = strActivePrinter
End Sub
and would appreciate any tips on how to avoid the pop-up dialog that appears when I run this macro.
My goal is to be able to print off a set of documents without any user intervention.
There's nothing heavier than an empty water bottle

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: suppress "print to file" dialog (Word 2000)

Post by Leif »

Dunno if it is any help, but this is what I use to print to PDFCreator:

Code: Select all

Sub PDF()
'
' PDF Macro
Dim strOriginalPrinter As String, iNE As Integer, sTemp As String
strOriginalPrinter = Application.ActivePrinter
On Error Resume Next
iNE = 0
TryAgain:
On Error Resume Next
sTemp = "PDFCreator on Ne0" & CStr(iNE) & ":"
    Application.ActivePrinter = sTemp
    If Err.Number <> 0 And iNE < 9 Then iNE = iNE + 1: GoTo TryAgain
If Err.Number <> 0 Then
    Call MsgBox("PDFCreator printer port not found!", vbExclamation, "PDFCreator not found")
    Application.ActivePrinter = strOriginalPrinter
    Exit Sub
End If
Application.PrintOut
Application.ActivePrinter = strOriginalPrinter
End Sub
I found that PDFCreator could be installed on varying ports in different PCs, hence polling through the 'Ne' numbers.
Leif

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15615
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: suppress "print to file" dialog (Word 2000)

Post by ChrisGreaves »

Leif wrote:Dunno if it is any help, but this is what I use to print to PDFCreator:
Thanks for code Leif.
It runs on my system when substitute "PrimoPDF" for "PDFCreator" (and in the process I learned that PDFill PDF&Image Writer on NE06:!) but still I get the little pop-up dialog.

It runs on my system when substitute "PDFill PDF&Image Writer" for "PDFCreator"but this printer generates the regular File-save-As dialog, still requiring me to choose "OK for each file.

Then I realized that you had merely "Application.PrintOut" whereas I had "Application.PrintOut blah-blah-blah", so I did the unthinkable:
I read the help file, and waddyaknow:

Code: Select all

PrintToFile:=True, outputfilename:="b:\5331.pdf"
dispelled the dialog box.

So Thank You Leif!
Your response sent me off in the direction I could have followed from the start.
All I need do now is substitute a variable file name for the hard-coded and I am, as we say in the trade, up-and-running.

Code: Select all

Sub test()
    Dim strActivePrinter As String
    strActivePrinter = ActivePrinter
    
    ActivePrinter = "PrimoPDF"
'    ActivePrinter = "PDFill PDF&Image Writer"
    
    Dim strFileName As String
    strFileName = Format(Now(), "hhmmss")
    Application.PrintOut FileName:=ThisDocument.FullName, Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        Collate:=True, Background:=True, PrintToFile:=True, outputfilename:="b:\5331.pdf", PrintZoomColumn:=0, _
        PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
    
    ActivePrinter = strActivePrinter
End Sub
There's nothing heavier than an empty water bottle

User avatar
Leif
Administrator
Posts: 7209
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: suppress "print to file" dialog (Word 2000)

Post by Leif »

ChrisGreaves wrote: So Thank You Leif!
No, no, no - not me! I'm fairly sure I got the code from Hans, who as we all know, invented VBA some years ago during a coffee break...
Leif

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15615
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: suppress "print to file" dialog (Word 2000)

Post by ChrisGreaves »

Leif wrote:invented VBA some years ago during a coffee break...
At last!
Someone we can blame! :laugh:
There's nothing heavier than an empty water bottle