VBA Help PDF Creator

RiosM

New Member
Joined
Mar 24, 2014
Messages
1
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:

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
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,216,073
Messages
6,128,634
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top