I’m trying to use a macro to get an Excel document to print itself to a PDF file. I’m using Excel 2003 on Windows XP with PdfCreator 1.5.0
The problem is that PDFCreator1.cCountOfPrintjobs always stays 0. The UI doesn’t show the file that I’m printing either.
If I kill PdfCreator by force, and print a file from another application (e.g. print a text file from notepad++, by clicking the print button with my mouse), then the original excel file is listed in the print queue.
How do I get PdfCreator to recognise the printed file is my macro?
This is the VBA code I use to print the document:
Public Sub CreatePdfFromActiveSheet()
Dim gestart As Boolean
Dim PDFCreator1 As PDFCreator.clsPDFCreator
Set PDFCreator1 = New clsPDFCreator
gestart = PDFCreator1.cStart("/NoProcessingAtStartup")
If gestart = False Then
Err.Raise Number:=440, Description:=“Can’t initialize PDFCreator.”
Exit Sub
End If
PDFCreator1.cOption(“UseAutosave”) = 1
PDFCreator1.cOption(“UseAutosaveDirectory”) = 1
PDFCreator1.cOption(“AutosaveDirectory”) = ActiveWorkbook.Path
PDFCreator1.cOption(“AutosaveFilename”) = "Raamwerkovereenkomst.pdf"
PDFCreator1.cOption(“AutosaveFormat”) = 0 ’ 0 = PDF
PDFCreator1.cClearCache
Application.ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until PDFCreator1.cCountOfPrintjobs = 1
DoEvents
Sleep 1000
Loop
PDFCreator1.cPrinterStop = False
Do Until PDFCreator1.cCountOfPrintjobs = 0
DoEvents
Sleep 100
Loop
PDFCreator1.cClose
Set PDFCreator1 = Nothing
End Sub
I tried again with PdfCreator 1.3.2, and it worked as expected.