PDF creator stop working

drocha

New member
Joined
Feb 15, 2012
Messages
5
Reaction score
0
Points
0
Location
Porto, Portugal
Hello,

I use your code to create a pdf file and sending it by an e-mail.

I use this code for over a year, but now it stop working, apparently it comes to a loop and doesn’t continue the code.
I already tried the code you suggest in an old post with the same problem, but it doesn’t work again.

Could you help me?
Thanks

I send the code I currently use:


Sub Cria_PDF()
'Author : Ken Puls 'Macro Purpose: Print to PDF file using PDFCreator
' Designed for late bind, no references req'd
Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
Dim mes As String
Dim bytLoops As Integer

mes = Format(Now() - 50, "mmm yyyy")

Sheets("CE").Select
'/// Change the output file name here! ///
sPDFName = "analise custos e investimentos - " & Range("v1") & " - " & mes & ".pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
' MsgBox "Can't initialize PDFCreator.", vbCritical + _
' vbOKOnly, "PrtPDFCreator"

'PDF Creator is already running. Kill the existing process
Shell "taskkill /f /im PDFCreator.exe", vbHide
DoEvents
Set pdfjob = Nothing
bRestart = True
'' Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
Sheets("CE").Select

If Range("l10").Value = 0 And Range("l16").Value = 0 And Range("l23").Value = 0 Then
'Print the document to PDF
Sheets(Array("CE", "Detalhe Equipa")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l10").Value = 0 And Range("l23").Value <> 0 Then
'Print the document to PDF
Sheets(Array("CE", "Detalhe Equipa", "Detalhe Projetos")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l10").Value <> 0 And Range("l23").Value = 0 Then
If Range("l11") = 0 And Range("l12") = 0 Then
'Print the document to PDF
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (SP)")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l13") = 0 And Range("l12") = 0 Then
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MH)")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l13") = 0 And Range("l11") = 0 Then
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MS)")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l11") = 0 Then
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MS)", "Detalhe M&S (SP)")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
Else
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MH)", "Detalhe M&S (MS)", "Detalhe M&S (SP)")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

End If

If Range("l10").Value <> 0 And Range("l23").Value <> 0 Then
If Range("l11") = 0 And Range("l12") = 0 Then
'Print the document to PDF
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (SP)", "Detalhe Projetos")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l13") = 0 And Range("l12") = 0 Then
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MH)", "Detalhe Projetos")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l13") = 0 And Range("l11") = 0 Then
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MS)", "Detalhe Projetos")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If

If Range("l11") = 0 Then
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MS)", "Detalhe M&S (SP)", "Detalhe Projetos")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
Else
Sheets(Array("CE", "Detalhe Equipa", "Detalhe M&S (MH)", "Detalhe M&S (MS)", "Detalhe M&S (SP)", "Detalhe Projetos")).Select
ActiveWindow.SelectedSheets.PrintOut copies:=1, ActivePrinter:="PDFCreator"
End If
End If

bytLoops = 0

'' Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1 Or bytLoops = 10
DoEvents
bytLoops = bytLoops + 1
Loop
pdfjob.cPrinterStop = False
'Wait until the file shows up before closing PDF Creator
Do
DoEvents
Loop Until Dir(sPDFPath & sPDFName) = sPDFName
pdfjob.cClose
Set pdfjob = Nothing
End Sub
 
Top