Results 1 to 4 of 4

Thread: Print PDF endless loop

  1. #1

    Print PDF endless loop



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello everyone!

    I was running an excel with Ken Puls Print PDF, early binding, with no problems in my previous computer. But now I've changed my workplace and computer and can't seem to have the macro working. I didn't change the code, I set the reference for PDFCreator and I have the same PDF Creator and excel versions as in the previous PC.
    The code gets stuck in the following code:
    Code:
    Do Until pdfjob.cCountOfPrintjobs = 1
        DoEvents
    Loop
    PDF Creator starts but without any print jobs making the previous loop an endless one.

    I do not have access to the code right now so I can't post it.

    Any ideas??

    Thank you.

  2. #2

    Print PDF endless loop - code

    And here is the code.
    Code:
    Option Explicit
    Sub PrintToPDF()
        'Author : Ken Puls 
        'Macro Purpose: Print to PDF file using PDFCreator
        ' Designed for early bind, set reference to PDFCreator
        
        Dim pdfjob As Object
        Dim sPDFName As String
        Dim sPDFPath As String
        Dim lSheet As Integer
        Dim pdfname, localPdfPath, meses As Variant
        Dim dta As String
        If (Len(Month(Date) < 10)) Then
            dta = Year(Date) & "0" & Month(Date) & Day(Date)
        Else
            dta = Year(Date) & Month(Date) & Day(Date)
        End If
        Dim Response, Style
        Style = vbOKCancel + vbQuestion + vbDefaultButton2
        Response = MsgBox("Quer realmente criar o PDF", Style, "Criar PDF's da Escala")
        If Response = vbCancel Then Exit Sub
           
       
        localPdfPath = "\\PDF"
    
        pdfname = dta & "_Escala " & Application.ActiveSheet.Range("O4") _
        & " " & Application.ActiveSheet.Range("P4") & " " & Application.ActiveSheet.Range("Q4") _
        & " " & Application.ActiveSheet.Range("R4") _
        & " " & Application.ActiveSheet.Range("S4") & " " & Application.ActiveSheet.Range("U4") _
        & " " & TranslateChar(Application.ActiveSheet.Range("AC4"))
        
       
        Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
        sPDFPath = ActiveWorkbook.path & Application.PathSeparator
    
        If pdfjob.cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't initialize PDFCreator.", vbCritical + _
                vbOKOnly, "PrtPDFCreator"
            Exit Sub
        End If
               
            If Not IsEmpty(ActiveSheet.UsedRange) Then
                With pdfjob
                    sPDFName = pdfname & ".pdf"
                    sPDFPath = localPdfPath
                    .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
                Worksheets(Application.ActiveSheet.name).PrintOut From:=1, To:=1, Copies:=1, ActivePrinter:="PDFCreator"
            
                '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
            End If
    
        pdfjob.cClose
    
        Set pdfjob = Nothing
    End Sub

  3. #3
    Definitely can't make it work.
    Still no ideas from the experts?
    Thank you!

  4. #4

    Solved

    After trying lots of different (possible) solutions I finally got this problem solved, and is as simple as a conflict that existed between PDFCreator and PDFArchitect. Uninstalled the later one and guess what problem solved.

    Hope this helps others with the same problem.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •