Hallo
ich will ein Tabellenblatt als pdf abspeichern.
Dank diesem Forum habe ich einen Code gefunden, welcher jedoch bei mir nicht richtig funktioniert.
Wenn ich bei Break (siehe Code) stoppe, ist der PDFCreator geöffnet, das umzuwandelne Tabellenblatt
ist eingetragen und der Status ist "Drucken".
Weiter passiert jedoch nicht. Bei diversen Versuchen ist es mir schon mal gelungen den Druck in der
PDFCreator Oberfläche zu starten. Das ist zwar nicht Sinn der Sache, aber danach läuft auch der weitere
VBA Code ohne Fehler durch.
Ohne Breakpoint dreht VBA in der letzten Do Loop Schleife Endlosrunden bis es irgenwann mal eine
Fehlermeldung gibt. (z.B. Speicherüberlauf)
Ich meine bei mir zu Hause mit gleicher Softwareumgebung aber langsamerem Rechner hat dieser Code
schon mal funktioniert.
Es wäre super, wenn mir jemand einen Tip geben könnte.
Vielen vielen Dank im Voraus
Gruß Horst
Sub PrintToPDF_Early(Blattname)
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from http://sourceforge.net/ _
_
projects/pdfcreator/)
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim DefaultPrinter
'/// Change the output file name here! ///
sPDFName = "Test.pdf"
'sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
sPDFPath = "C:\Temp\Repatest"
'Check if worksheet is empty and exit if so
If IsEmpty(Worksheets(Blattname).UsedRange) Then Exit Sub
Set pdfjob = New PDFCreator.clsPDFCreator
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
.cPrinterStop = False '
End With
'Print the document to PDF
Worksheets(Blattname).PrintOut copies:=1, ActivePrinter:="PDFCreator"
BreaK
'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
Sleep 250
Loop
MsgBox "PDF Dokument wurde erzeugt"
pdfjob.cClose
Set pdfjob = Nothing
End Sub