um eine Arbeitsmappe als PDF zu speichern, bemühe ich den "PDFCreator" sowie den Drucken-Dialog. _ Der Recorder gibt mir dann folgendes:
Sub Makro1()
Application.ActivePrinter = "PDFCreator auf Ne00:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator auf Ne00:", Collate:=True
End Sub
Nun muss ich natürlich noch von Hand den Dateinamen der PDF, den Speicherort usw angeben und auf OK drücken. Das scheint mir sehr unkomfortabel, wenn ich viele Arbeitsmappen auf verschiedene Verzeichnisse verteilt PDF-en möchte. Eine Krücke über SENDKEYS könnte ich mir zwar bauen, das scheint mir aber nicht zielführend und sehr fehleranfällig.
Meine Recherche hat folgende Lösung gefunden (Code nochmal unten angehängt)
http://www.excelguru.ca/node/21
Das könnte ich mir bestimmt auf meine Bedürfnisse umstricken - wenn es denn liefe. Bereits in der ersten Programmzeile,
Dim pdfjob As PDFCreator.clsPDFCreator
steigt mir das Beispielmakro aus mit der Fehlermeldung:
Fehler beim Kompilieren: Benutzerdefinierter Typ nicht definiert.
Woran kann das liegen? Kann jemand helfen?
Option Explicit
Sub PrintToPDF_Early()
'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
'/// Change the output file name here! ///
sPDFName = "testPDF.pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.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
End With
'Print the document to PDF
ActiveSheet.PrintOut 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
pdfjob.cClose
Set pdfjob = Nothing
End Sub
Grüße,
Klaus M.vdT.