Count of print jobs error

Hi,

I'm using PDF Creator within excel macro, but unfortunately print job always stuck in spooler. I don't know how to solve this. Please look at my macro below.

I always recieve PDF print but macro is unable to count it a finish procedure.

Also this one is working in excel 2007, but when I use it in 2003 it won't even PDF print out. This one work, but when I turn on Auto Save option, after execution nothing happens, it goes to spooler but without any print out.

I would appreciate if someone can help me to solve this.

Thanks in advance

M

 


With PrintPDF
   
    PrintPDF.cPrinterStop = True
   
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = SaveStr
        .cOption("AutosaveFilename") = FName
        .cOption("AutosaveFormat") = 0    ' 0 = PDF
        .cClearCache
       
End With

ActiveWorkbook.Worksheets("PONUDA").PrintOut copies:=1, ActivePrinter:="PDFCreator"


    Do Until PrintPDF.cCountOfPrintjobs = 1
        DoEvents
    Loop
    PrintPDF.cPrinterStop = False

    Do Until PrintPDF.cCountOfPrintjobs = 0
        DoEvents
    Loop
    PrintPDF.cClose
    Set PrintPDF = Nothing
   
    Exit Sub
   
End Sub

 

I can't really say I entirely know what I'm doing, but I did some trial and error trying to write a similar macro.  What I ended up with was similar to what you have, but after:

PrintPDF.cPrinterStop = False

I included another DoEvents instruction.  Whatever timing problems I must have had seemed to get cleared.  So I ended up w/ somethinglike this:

    'Print the document to PDF
        ActiveSheet.PrintOut Copies:=1, Collate:=True
    'Wait until the print job has entered the print queue
        Do Until pdfjob.cCountOfPrintjobs = 1
            DoEvents
        Loop
        pdfjob.cPrinterStop = False
        DoEvents    '<<<<< new line
    'Wait until PDF creator is finished then release the objects
        Do Until pdfjob.cCountOfPrintjobs = 0
            DoEvents
        Loop

Hope this helps.