How to batch convert multiple Word documents to pdf files?
It is easy for you to convert a Word document to a PDF file with the Save as function in Word. But if you want to convert all Word documents in a folder to separate PDF files at once, how can you achieve it? This article will show you a VBA code to batch convert multiple Word documents to pdf files in Word.
Batch convert multiple Word documents to pdf files with VBA
Batch convert multiple Word documents to pdf files with Kutools for Word
Batch convert multiple Word documents to pdf files with VBA
The following VBA code helps you quickly convert all Word documents in a folder to pdf files at once. Please do as follows.
1. In Word, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below VBA code into the Module window.
VBA code: Batch convert multiple Word documents to pdf files 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. Press the F5 key to run the code.
4. A Browse dialog pops up, please select the folder which contains Word documents you will convert to pdf files, and click the OK button.
Then all Word documents in selected folder are converted to separate pdf files at once. See screenshot:
Batch convert multiple Word documents to pdf files with Kutools for Word
If VBA code is hard to handle, you can try the Convert documents utility of Kutools for Word to solve the problem.
Kutools for Word : With more than 100 handy Word add-ins, free to try with no limitation in 60 days.
1. Click Kutools Plus > Doc/Docx. See screenshot:
2. In the Document Format Converter window, you need to do as follows:
3. Then a dialog box pops up to tell you how many documents have been successfully converted, click the OK button and close the Document Format Converter window.
Now all .docx format documents are converted to pdf files.
If you want to have a free trial of this utility, please go to free download the software first, and then go to apply the operation according above steps.
Best Office Productivity Tools
Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!
🤖 Kutools AI Assistant: Transform your writing with AI - Generate Content / Rewrite Text / Summarize Documents / Inquire for Information based on Document, all within Word
📘 Document Mastery: Split Pages / Merge Documents / Export Selection in Various Formats (PDF/TXT/DOC/HTML...) / Batch Convert to PDF / Export Pages as Images / Print Multiple Files at once...
✏ Contents Editing: Batch Find and Replace across Multiple Files / Resize All Pictures / Transpose Table Rows and Columns / Convert Table to Text...
🧹 Effortless Clean: Sweap away Extra Spaces / Section Breaks / All Headers / Text Boxes / Hyperlinks / For more removing tools, head to the Remove group...
➕ Creative Inserts: Insert Thousand Separators / Check Boxes / Radio Buttons / QR Code / Barcode / Diagonal Line Table / Equation Caption / Image Caption / Table Caption / Multiple Pictures / Discover more in the Insert group...
🔍 Precision Selections: Pinpoint Specific Pages / Tables / Shapes / Heading Paragraphs / Enhance navigation with more Select features...
⭐ Star Enhancements: Navigate to Any Location / Auto-Insert Repetitive Text / Toggle Between Document Windows / 11 Conversion Tools...