PDF erzeugen per VBA
02.03.2014 20:07:37
Mercedesmann
ich hoffe wie immer Hilfe hier zu bekommen. :-) Ich habe ein Makro, welches mir einen PDF Ausdruck eines Tabellenblattes macht und unter einem bestimmten Pfad speichert. Das funktioniert soweit auch prima. Nun möchte ich aber, dass die PDF den Names aus dem Tabellenblatt Namen und dem aktuellen Datum nimmt und dann Outlook öffnet und diese PDF an eine Mailadresse schickt. Jemand eine Idee? Das vorhandene Makro sieht so aus.
Function Ausdruck_PDF(PathStr As String, FileStr As String) As Boolean
Dim pdfJob As Object
'On Error GoTo Hell
Set pdfJob = CreateObject("PDFCreator.clsPDFCreator") 'New PDFCreator.clsPDFCreator
With pdfJob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
GoTo Hell
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
With pdfJob
.cOption("AutosaveDirectory") = PathStr
.cOption("AutosaveFilename") = FileStr
End With
Worksheets("Einsatzplan").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
Ausdruck_PDF = True
Hell:
pdfJob.cClose
Set pdfJob = Nothing
End Function
Gruß Willi