Print Excel Sheet

As your code is likely to be different to mine, could you provide a listing of the code please?
I can then have a look at it to try to work out why it is not working for you.
Could you also say how many worksheets are being printed.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Ok, well first I just got it to work by adding in
Code:
Shell ("C:\Program Files\PDFCreator\PDFCreator.exe")
right after my code. Now I need to figure out how to close this same PDFCreator back out within my code. But here is my code (minus the newly added bit at the end):

Code:
Sub PrintToPDF_MultiSheetToOne_Early()

    Dim pdfjob As PDFCreator.clsPDFCreator
    Dim sPDFName As String
    Dim sPDFPath As String
    Dim lSheet As Long
    Dim lTtlSheets As Long

    '/// Change the output file name here! ///
    sPDFName = "PES Receipt.pdf"
    sPDFPath = "X:\Logbook\"
    Set pdfjob = New PDFCreator.clsPDFCreator

    'Make sure the PDF printer can start
    If pdfjob.cStart("/NoProcessingAtStartup") = False Then
        MsgBox "Can't initialize PDFCreator.", vbCritical + _
                vbOKOnly, "Error!"
        Exit Sub
    End If

    'Set all defaults
    With pdfjob
        .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
    lTtlSheets = Application.Sheets.Count
    For lSheet = 1 To Application.Sheets.Count
        On Error Resume Next 'To deal with chart sheets
        If Not IsEmpty(Application.Sheets(lSheet).UsedRange) Then
            Application.Sheets(lSheet).PrintOut copies:=1, ActivePrinter:="PDFCreator"
        Else
            lTtlSheets = lTtlSheets - 1
        End If
        On Error GoTo 0
    Next lSheet

    'Wait until all print jobs have entered the print queue
    Do Until pdfjob.cCountOfPrintjobs = lTtlSheets
        DoEvents
    Loop

    'Combine all PDFs into a single file and stop 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
Application.Wait Now() + TimeValue("00:00:" & Right("00" & Trim(Str(intPDF_Time_Delay)), 2))
    pdfjob.cClose
    Set pdfjob = Nothing
    
    'Application.Wait Now() + TimeValue("00:00:" & Right("00" & Trim(Str(intPDF_Time_Delay)), 2))
'pdfjob.cClose
'Set pdfjob = Nothing
End Sub
 
Upvote 0
I have three observations:
1. intPDF_Time_Delay has not been declared (Dim intPDF_Time_Delay as Integer) and consequently has not been given a value. Since the process is not failing I guess that it is using zero?
2. I also have an "Application.Wait" immediately after the "PrintOut" line.
3. Instead of "New PDFCreator.clsPDFCreator" I use CreateObject but I would not expect that to make a difference.
My usual 'wait' period is 5 seconds and that is usually enough but occasionally I need to set it to 10 seconds.
 
Upvote 0
I am getting it to work everytime now by adding the code
Code:
Shell ("C:\Program Files\PDFCreator\PDFCreator.exe")
after.

I'm not sure if your changes will fix this for me, nor do I know enough to make those changes. I guess all I need it code on how to close the same program I opened above, because it will not work a second time when the PDFCreator is opened (unless, I maybe made changes in the code, which I do not know how to do).
 
Upvote 0
I am just trying to print my active Excel 2003 sheet to my "Bullzip PDF Printer". Is there a version of this code (post of Aug 5th, 2010 11:20 AM) in 2003 that will do that?

Here's the code I'm using to display the pdf "save" dialog. I then need to either click oni ts"Save" button or press Enter, then again to verify overwrite, then Ctrl-Q to close the saved .pdf. The Sendkeys ("~") doesn't work. Macro just hangs up there on the first one.

Range("C2:O48").Select 'Highlights the print area for chart and table for pdf
Application.ActivePrinter = "Bullzip PDF Printer on Ne05:" 'Chooses BullZip PDF printer for printing
Selection.PrintOut Copies:=1, ActivePrinter:="Bullzip PDF Printer on Ne05:" Displays Save .pdf dialog

' SAVE .PDF
Application.SendKeys ("~")

' OVERWRITE EXISTING .PDF
Application.SendKeys ("~")

' CLOSE .PDF
Application.SendKeys ("^Q")

Thanks much for any help available.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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