Home Credits Impressum more

PDF-Dateien per Makro aus Word-Dateien heraus erzeugen

Aus Microsoft Word heraus PDF-Dateien zu erzeugen ist mittlerweile kein Problem mehr. Mit einem Makro, das ich im Internet entdeckt habe, geht es besonders schnell.

Das Erzeugen von PDF-Datein kommt bei der Arbeit mit Microsoft Word häufig vor. Die Speichern-Funktion ist über einen Mausklick erreichbar. Warum nicht auch die Als-PDF-speichern-Funktion?

Nach dem Starten des Makros wird eine Eingabemaske angezeigt. Dort kann man den Dateinamen eingeben. Vorgeschlagen wird der Dateiname der Word-Datei.

Sie können das folgende Makro einfach per Copy&Paste übernehmen:

Sub AlsPDFSpeichern()
   
    Dim strPath     As String
    Dim strPDFname  As String
   
    Dim pathName    As String
    Dim o           As Document
    Set o = ActiveDocument
   
    strPDFname = InputBox("Geben Sie den Namen der PDF-Datei ein:", "File Name", Left(o.Name, InStrRev(o.Name, ".") - 1))
    If strPDFname = "" Then
        strPDFname = "example"
    End If
    strPath = ActiveDocument.Path
    If strPath = "" Then
        strPath = Options.DefaultFilePath(wdDocumentsPath) & Application.PathSeparator
    Else
        strPath = strPath & Application.PathSeparator
    End If
    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
                                       strPath & strPDFname & ".pdf", _
                                       ExportFormat:=wdExportFormatPDF, _
                                       OpenAfterExport:=False, _
                                       OptimizeFor:=wdExportOptimizeForPrint, _
                                       Range:=wdExportAllDocument, _
                                       IncludeDocProps:=True, _
                                       CreateBookmarks:=wdExportCreateWordBookmarks, _
                                       BitmapMissingFonts:=True
End Sub

Quellen

https://stackoverflow.com/questions/74214712/excel-vba-open-input-box-in-word-from-excel-vba-code
https://www.msofficeforums.com/word-vba/45987-vba-save-word-document-pdf-default-location.html