Problem:
How can I automate printing a Microsoft Word document to Win2PDF?
Solution:
The following sample code uses Microsoft Word and Win2PDF to create PDF files. The sample code bypasses Win2PDF's File Save dialog.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim WdApp As Object
Set WdApp = CreateObject("Word.Application")
'save path and file name in registry for Win2PDF, to bypass file prompt
SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFPostFileName", "c:\myfile.pdf"
With WdApp
.Documents.Open FileName:="c:\myfile.doc"
.Options.PrintBackground = True
.ActivePrinter = "Win2PDF"
.Visible = False
.ActiveDocument.PrintOut
.Documents.Close savechanges:=False
End With
'Verify Win2PDF is done creating PDF file
Do
Sleep 10
PDFRegKey = GetSetting("Dane Prairie Systems", "Win2PDF", "PDFPostFileName", "")
Loop While PDFRegKey Empty