Option Explicit
Sub PrintToPDF_Late()
'Author : Ken Puls ([URL="http://www.excelguru.ca/"][COLOR=#417394]www.excelguru.ca[/COLOR][/URL])
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from [URL="http://sourceforge.net/projects/pdfcreator/"][COLOR=#417394]http://sourceforge.net/projects/pdfcreator/[/COLOR][/URL])
' Designed for late bind, no references req'd
Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
'/// Change the output file name here! ///
sPDFName = "testPDF.pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Combine all jobs already in the PDFCreator queue
pdfjob.cCombineAll = False
pdfjob.cPrinterStop = False
'Wait until the file shows up before closing PDF Creator
Do
DoEvents
Loop Until Dir(sPDFPath & sPDFName) = sPDFName
pdfjob.cClose
Set pdfjob = Nothing
End Sub