Hi all. I have this VBA using 3rd party PDF printer to print a sheet PDF & it was working fine but for some reason the code does not close the PDF printer app. The problem lines are
Can anyone see what needs fixing? I have experimented where to to put the "Sleep 1000" value maybe I need more?
Code:
'Sleep 1000
pdfjob.cClose
'Needed to close PDFCreator
Sleep 1000
Set pdfjob = Nothing
Can anyone see what needs fixing? I have experimented where to to put the "Sleep 1000" value maybe I need more?
Code:
Option Explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub PrintToPDF_Late_Lionels()
'testing May 22
'Modified 22/02/09 for Civic Invoice 09.xls
'http://www.mrexcel.com/forum/showthread.php?t=345461
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/projects/pdfcreator/)
' Designed for late bind, no references req'd
Dim pdfjob As Object
'Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
'/// Change the output file name here! ///
Application.ScreenUpdating = False
With ActiveWorkbook
sPDFName = "Civic Invoice " & Range("F5") & ".pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
End With
'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
'Print the document to PDF
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
'Needed to close PDFCreator
Sleep 1000
Set pdfjob = Nothing
Application.ScreenUpdating = True
End Sub