PDFCreator automation in VBA Excel
Thank you for reading this.
I am trying to automate the creation of pdf documents from word documents in excel. I am using PDFCreator.
I found the different bits of code below online.
However I have two issues:
- a pop up windows comes up and use nothing of the settings I asked for folder where to save. (ideally I would not even want that window to pop up so that I have a full automation).
- It seems to look indefinitely in the end.
Any help would be great. this is driving me insane ;-)
cheers
Julien
[VBA]Sub GeneratePDF(ByVal sDocumentToConvert As String, ByVal sValue As String, ByVal sNewFolder As String)
Dim pdfjob As PDFCreator.clsPDFCreator
Dim p
p = ActivePrinter
WordApp.ActivePrinter = "PDFCreator"
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sNewFolder
.cOption("AutosaveFilename") = sValue
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
wrdDoc.PrintOut
'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
Set pdfjob = Nothing
ActivePrinter = p
End Sub[/VBA]