Hello, I dont know what I am doing wrong in this script, but its not giving any file output, I want to Export to ONE pdf several pivot tables and pages, then save them in a directory with a specified filename from a cell..
the code:
I will appreciate any help =D
the code:
Code:
Sub PrintToPDF()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
'return to old printer at the end
Dim oldPrinter As String
oldPrinter = Application.ActivePrinter
'Change the filename and output directory
sPDFName = "EDC-" & Sheet3.Range("C1").Value
sPDFPath = "C:\Print Tests\"
'Delete the PDF if it already exists
If Dir(sPDFPath & sPDFName) = sPDFName Then Kill (sPDFPath & sPDFName)
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator because it is open, will be automatically closed, Press again the Print Button.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Shell "taskkill /f /im PDFCreator.exe", vbHide
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
Sheet7.Range("A3").PivotTable.TableRange2.PrintOut
Sheet1.Range("A3").PivotTable.TableRange2.PrintOut
'Wait until all the documents are sent,
Do Until pdfjob.cCountOfPrintjobs = 3
DoEvents
Loop
pdfjob.cPrinterStop = False
'Combine all PDFs into a single file and start the printer
With pdfjob
.cCombineAll
.cPrinterStop = False
End With
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
Application.ActivePrinter = oldPrinter
MsgBox "PDF Succesfully Created "
Shell "explorer.exe" & " " & sPDFPath, vbNormalFocus
End Sub
I will appreciate any help =D