Direkt zum Inhalt

Wie kann ich mehrere Word-Dokumente stapelweise in PDF-Dateien konvertieren?

Mit der Funktion Speichern unter in Word können Sie ein Word-Dokument ganz einfach in eine PDF-Datei konvertieren. Wenn Sie jedoch alle Word-Dokumente in einem Ordner gleichzeitig in separate PDF-Dateien konvertieren möchten, wie können Sie dies erreichen? Dieser Artikel zeigt Ihnen einen VBA-Code zum Batch-Konvertieren mehrerer Word-Dokumente in PDF-Dateien in Word.

Batch-Konvertierung mehrerer Word-Dokumente in PDF-Dateien mit VBA
Batch-Konvertierung mehrerer Word-Dokumente in PDF-Dateien mit Kutools for Word


Batch-Konvertierung mehrerer Word-Dokumente in PDF-Dateien mit VBA

Mit dem folgenden VBA-Code können Sie schnell alle Word-Dokumente in einem Ordner gleichzeitig in PDF-Dateien konvertieren. Bitte gehen Sie wie folgt vor.

1. Drücken Sie in Word die Taste Andere + F11 Schlüssel zum Öffnen der Microsoft Visual Basic für Applikationen Fenster.

2. In dem Microsoft Visual Basic für Applikationen Klicken Sie im Fenster Insert > ModulKopieren Sie dann den folgenden VBA-Code in das Modulfenster.

VBA-Code: Batch-Konvertierung mehrerer Word-Dokumente in PDF-Dateien in Word

Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20181123
    Dim xIndex As String
    Dim xDlg As FileDialog
    Dim xFolder As Variant
    Dim xNewName As String
    Dim xFileName As String
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1) + "\"
    xFileName = Dir(xFolder & "*.*", vbNormal)
    While xFileName <> ""
        If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then
            xIndex = InStr(xFileName, ".") + 1
            xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")
            Documents.Open FileName:=xFolder & xFileName, _
                ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
                PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
                WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
                wdOpenFormatAuto, XMLTransform:=""
            ActiveDocument.ExportAsFixedFormat OutputFileName:=xFolder & xNewName, _
                ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
                wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
                Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
                CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
                BitmapMissingFonts:=True, UseISO19005_1:=False
            ActiveDocument.Close
        End If
        xFileName = Dir()
    Wend
End Sub

3. Drücken Sie die Taste F5 Schlüssel zum Ausführen des Codes.

4. Ein Dialogfeld zum Durchsuchen wird angezeigt. Wählen Sie den Ordner aus, der Word-Dokumente enthält, die Sie in PDF-Dateien konvertieren möchten, und klicken Sie auf OK .

Anschließend werden alle Word-Dokumente im ausgewählten Ordner gleichzeitig in separate PDF-Dateien konvertiert. Siehe Screenshot:


Batch-Konvertierung mehrerer Word-Dokumente in PDF-Dateien mit Kutools for Word

Wenn VBA-Code schwer zu handhaben ist, können Sie das versuchen Dokumente konvertieren Nutzen von Kutools for Word um das Problem zu lösen.

Kutools for Word : Mit mehr als 100 praktischen Word-Add-Ins, Kostenlos zum Ausprobieren ohne Einschränkung 60 Tage.

1 Klicken Kutoolen Plus > Doc / Docx. Siehe Screenshot:

2. In dem Dokumentformatkonverter Fenster müssen Sie wie folgt vorgehen:

2.1) Wählen Sie den Ordner aus, der Dokumente enthält, die Sie in PDF konvertieren möchten Quelldateiordner Sektion;
2.2 Select Konvertieren Sie docx in pdf von dem Format konvertieren Dropdown-Liste;
2.3) Standardmäßig ist die Zielpfad wie Quelle Kontrollkästchen ist aktiviert. Wenn Sie alle konvertierten PDF-Dateien im selben Ordner ablegen möchten, lassen Sie diese Option einfach ausgewählt.
Wenn Sie die PDF-Dateien und die Quelldokumente trennen möchten, müssen Sie das Kontrollkästchen deaktivieren Zielpfad wie Quelle und wählen Sie einen neuen Ordner aus, um die PDF-Dateien im zu speichern Sparen Sie bis zu Box;
2.4) Klicken Sie auf Startseite Taste. Siehe Screenshot:

3. Anschließend wird ein Dialogfeld angezeigt, in dem Sie erfahren, wie viele Dokumente erfolgreich konvertiert wurden. Klicken Sie auf OK Taste und schließen Sie die Dokumentformatkonverter Fenster.

Jetzt werden alle Dokumente im DOCX-Format in PDF-Dateien konvertiert.

Wenn Sie dieses Dienstprogramm kostenlos testen möchten, gehen Sie zu Laden Sie die Software kostenlos herunter Wenden Sie zuerst die Operation gemäß den obigen Schritten an.

Beste Office-Produktivitätstools

Kutools for Word - Steigern Sie Ihr Word-Erlebnis mit Over 100 Bemerkenswerte Funktionen!

🤖 Kutools KI-Assistent: Verwandeln Sie Ihr Schreiben mit KI – Inhalte generieren  /  Text umschreiben  /  Dokumente zusammenfassen  /  Erkundigen Sie sich nach Informationen basierend auf Dokument, alles in Word

📘 Dokumentenbeherrschung: Seiten teilen  /  Dokumente zusammenführen  /  Auswahl in verschiedenen Formaten exportieren (PDF/TXT/DOC/HTML...)  /  Stapelkonvertierung in PDF  /  Seiten als Bilder exportieren  /  Drucken Sie mehrere Dateien gleichzeitig...

Inhaltsbearbeitung: Batch suchen und ersetzen über mehrere Dateien hinweg  /  Größe aller Bilder ändern  /  Vertauschen Sie Tabellenzeilen und -spalten  /  Tabelle in Text konvertieren...

🧹 Mühelose Reinigung: Wegfegen Zusätzliche Räume  /  Abschnittswechsel  /  Alle Header  /  Textfelder  /  Hyperlinks  / Weitere Entfernungswerkzeuge finden Sie auf unserer Gruppe entfernen...

Kreative Einsätze: Einfügen Tausend Trennzeichen  /  Kontrollkästchen  /  Radio Knöpfe  /  QR Code  /  Strichcode  /  Diagonale Linientabelle  /  Gleichungsbeschriftung  /  Bildunterschrift  /  Tabellenüberschrift  /  Mehrere Bilder  / Entdecken Sie mehr im Gruppe einfügen...

🔍 Präzise Auswahl: Punktgenau bestimmte Seiten  /  Tabellen  /  Formen  /  Überschriften von Absätzen  / Verbessern Sie die Navigation mit mehr Wählen Sie Funktionen aus...

Star-Verbesserungen: Navigieren Sie schnell zu jedem Ort  /  Sich wiederholenden Text automatisch einfügen  /  Wechseln Sie nahtlos zwischen Dokumentfenstern  /  11 Konvertierungstools...

👉 Möchten Sie diese Funktionen ausprobieren? Kutools für Word bietet a 60-Tage kostenlose Testversion, ohne Einschränkungen! 🚀
 
Comments (36)
Rated 5 out of 5 · 3 ratings
This comment was minimized by the moderator on the site
Just found this, very helpful. Also thanks for the suggested mods above. I am struggling with the following:

If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then


It seems to ask to do the conversion if it's not a doc or docx? (Leaving aside that, I think, for docx it should be last 5 chars, not 4?) Anyway,
This comment was minimized by the moderator on the site
the code stopped. I clicked debug. code below was highlighed yellow

Please, any assistance? thank you

Documents.Open Filename:=xFolder & xFileName, _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
This comment was minimized by the moderator on the site
Thank you for this. It has just saved me so much time and provided education. I will peruse your site for more top tips.
Thank you again. Brilliant quick fix. One does have to ask, why do MS make such things so impossible to find in their products.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Здравствуйте! Огромное спасибо за модуль! Но есть проблема, у меня куча папок и в каждой папке больше двухсот файлов с разными именами.. Можно ли сделать так чтобы ваш модуль сохранял файлы в PDF не под номерами 1,2,3... и т.д, а под своими собственными именами файлов!? Помогите пожалуйста, и я буду молиться за вас ВЕЧНО!!))
This comment was minimized by the moderator on the site
Hi Егор,
I don't quite understand your question. After converting the file using the VBA code, the name of the PDF file is the same as the name of the Word file.
This comment was minimized by the moderator on the site
Здравствуйте! Большое спасибо вам, за то что вы есть! Спасибо за код он почти идеальный, но ОЧЕНЬ прошу Вас помочь с одним нюансом... Мне Очень важно чтоб ваш макрос сохранял в PDF не под номерами 1.2.3 и т.д, а брал название вордовского файла и сохранял под ним. У меня сто папок и в каждой по 251 файл со своим собственным названием... Мне это Очень нужно, пожалуйста помогите!?????.....
This comment was minimized by the moderator on the site
The VBA macro worked like a charm! :D
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Myles,
Thank you for your feedback.
This comment was minimized by the moderator on the site
Hello is there a way to select a different output folder and not the original folder?

thank you
This comment was minimized by the moderator on the site
Hi Vincent,
Please try the following VBA code. After running the code, an Open window pops up, please select a folder containing the douments you want to convert, in the second popping up Save PDF files in window, select a folder to save the PDF files.

Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20220805
  Dim xIndex As String
  Dim xDlg As FileDialog, xSaveDlg As FileDialog
  Dim xFolder As Variant, xSaveFolder As Variant
  Dim xNewName As String
  Dim xFileName As String
  On Error Resume Next
  Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
  xDlg.Title = "Open"
  xDlg.ButtonName = "Open"
  If xDlg.Show <> -1 Then Exit Sub
  xFolder = xDlg.SelectedItems(1) + "\"
  xFileName = Dir(xFolder & "*.*", vbNormal)
  Set xSaveDlg = Application.FileDialog(msoFileDialogFolderPicker)
  xSaveDlg.Title = "Save PDF files in"
  xSaveDlg.ButtonName = "Save"
  If xSaveDlg.Show <> -1 Then Exit Sub
  xSaveFolder = xSaveDlg.SelectedItems(1) + "\"
  Application.DisplayAlerts = wdAlertsNone
  While xFileName <> ""
      If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then
          xIndex = InStr(xFileName, ".") + 1
          xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")
          Documents.Open FileName:=xFolder & xFileName, _
              ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
              PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
              WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
              wdOpenFormatAuto, XMLTransform:=""
          ActiveDocument.ExportAsFixedFormat OutputFileName:=xSaveFolder & xNewName, _
              ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
              wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
              Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
              CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
              BitmapMissingFonts:=True, UseISO19005_1:=False
          ActiveDocument.Close wdSaveChanges
      End If
      xFileName = Dir()
  Wend
  Application.DisplayAlerts = wdAlertsAll
  Set xDlg = Nothing
  Set xSaveDlg = Nothing
End Sub
This comment was minimized by the moderator on the site
The code does not convert my Word files
This comment was minimized by the moderator on the site
This code is amazing and fast but if there is a link in the Doc file it will open a window stating there may be information linked to another file apply these changes? and then another asking to save as. Is there a way to add to the code to automatically do these steps for me? Out of ~800 there are ~40 and I must be present and do this every time.
thank you
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Vincent,
The following VBA code can do you a favor. Please give it a try. Thank you for your feedback.

Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20220805
  Dim xIndex As String
  Dim xDlg As FileDialog
  Dim xFolder As Variant
  Dim xNewName As String
  Dim xFileName As String
  On Error Resume Next
  Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
  If xDlg.Show <> -1 Then Exit Sub
  xFolder = xDlg.SelectedItems(1) + "\"
  xFileName = Dir(xFolder & "*.*", vbNormal)
  Application.DisplayAlerts = wdAlertsNone
  While xFileName <> ""
      If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then
          xIndex = InStr(xFileName, ".") + 1
          xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")
          Documents.Open FileName:=xFolder & xFileName, _
              ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
              PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
              WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
              wdOpenFormatAuto, XMLTransform:=""
          ActiveDocument.ExportAsFixedFormat OutputFileName:=xFolder & xNewName, _
              ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
              wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
              Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
              CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
              BitmapMissingFonts:=True, UseISO19005_1:=False
          ActiveDocument.Close wdSaveChanges
      End If
      xFileName = Dir()
  Wend
  Application.DisplayAlerts = wdAlertsAll
End Sub
This comment was minimized by the moderator on the site
Вот тут во втором условии надо 4 заменить на 5:
If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 5) <> ".docx") Then
Для исключения проблемы наличия точек можно сделать так:
xIndex = InStr(xFileName, ".doc") + 1
Ну и про советы других товарищей не забыть ;)

This comment was minimized by the moderator on the site
Thank you so much! Saved me so much time!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations