Home>Blogs>VBA>PDF to Word Converter Macro in Excel VBA: Convert Multiple PDFs
PDF to Word Converter Macro in Excel VBA: Convert Multiple PDFs
VBA

PDF to Word Converter Macro in Excel VBA: Convert Multiple PDFs

A PDF to Word converter macro in Excel VBA turns a whole folder of PDF files into editable Word documents with one click. You type two folder paths on a sheet, press a button, and the macro opens every PDF in Microsoft Word, saves it as a .docx file in the output folder and closes it again, while the status bar shows how many files are done. No API, add-in or online converter is needed: Word does the conversion and VBA does the repetitive work. This tutorial rebuilds the macro step by step, exactly as in the video.

PDF to Word converter macro in Excel VBA converting a folder of PDF files into Word documents
One folder of PDF files in, one folder of Word documents out, in a single click.

Watch the Video Tutorial

In the video PK builds the macro from a blank module, steps through it with F8, converts ten test PDFs into ten Word files, adds a progress counter in the status bar and finally switches to late binding so the file also runs on other Office versions.

PDF to Word Converter Macro in Excel VBA: What You Will Build

  • A settings sheet with an input folder for PDF files and an empty output folder for Word files.
  • A macro that loops through every file in the PDF folder with the File System Object.
  • Word automation: each PDF is opened in Word, saved as a .docx with the same name and closed.
  • A progress message such as Converting – 3/10 in Excel’s status bar and a message box at the end.
  • A Convert PDF to Word button that runs everything in one click.

This is the reverse of the Word to PDF converter in Excel VBA. The folder loop is the same; only the Word method at the end changes.

Part 1 – Set Up the Settings Sheet

Step 1: Create two folders and type their paths

Create two folders, for example PDF Files (put your PDFs here) and Word Files (keep it empty; the converted files land here).

In a new workbook, on Sheet1, type the labels and paste the full folder paths:

  • F4: the PDF files folder (input), for example C:\Users\YourName\Desktop\MyFolder\PDF Files.
  • F5: the Word files folder (output), for example C:\Users\YourName\Desktop\MyFolder\Word Files.
Excel settings sheet with the PDF files folder path, the Word files folder path and a Start Conversion button
The finished settings sheet: input folder, output folder and one button.

In the finished file shown above the sheet is renamed Settings and the paths sit in E4 and E5. If you use that layout, change "Sheet1", "F4" and "F5" in the code to match.

Step 2: Add the references

Open the Visual Basic Editor (Developer > Visual Basic or Alt+F11), choose Insert > Module, then go to Tools > References and tick:

  • Microsoft Scripting Runtime – gives you the File System Object, Folder and File types used to loop through the folder.
  • Microsoft Word 15.0 Object Library – lets Excel create and control Word. 15.0 is Office 2013, which the video uses; newer versions show 16.0. Pick the number your PC lists. (You can remove this one again in Part 4.)

Part 2 – Write the PDF to Word Converter Macro

Step 3: Declare the objects and read the paths

Create a subroutine called PDF_To_Word and declare the sheet, the File System Object, the Word objects and the two paths:

Option Explicit

Sub PDF_To_Word()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File

Dim wa As New Word.Application
Dim doc As Word.Document

wa.Visible = True

Dim pdf_path As String
Dim word_path As String

pdf_path = sh.Range("F4").Value
word_path = sh.Range("F5").Value

fso is the File System Object, fo will hold the PDF folder and f each file in it. wa must be a New Word application, otherwise there is nothing to open files with, and wa.Visible = True lets you watch Word while you test.

Step 4: Loop through the PDF folder and save each file as Word

Set fo = fso.GetFolder(pdf_path)

For Each f In fo.Files
    Set doc = wa.Documents.Open(f.Path)
    doc.SaveAs2 (word_path & "\" & Replace(f.Name, ".pdf", ".docx"))
    doc.Close False
Next

wa.Quit

How the code works

  • fso.GetFolder(pdf_path) returns the PDF folder as a Folder object, and For Each f In fo.Files visits every file in it. That is why the input folder should hold PDF files only.
  • wa.Documents.Open(f.Path) opens the PDF as a Word document. f.Path returns the complete path, file name and extension, which is exactly what Open needs. (f.Name would return only the name and extension.)
  • doc.SaveAs2 saves the opened document into the Word folder. The new name is the Word folder path, a backslash and the original name with .pdf replaced by .docx, so Test-1.pdf becomes Test-1.docx.
  • doc.Close False closes the document without saving again, because it has just been saved.
  • wa.Quit closes Word after the last file. Without it, Word stays open after the macro finishes, which is what happened in the first test run in the video.

Step 5: Test it with F8 and accept Word’s one-time message

Click inside the macro and press F8 to run it line by line. The first time, Word shows a message that it will convert the PDF into an editable Word document and that the result may not look exactly like the original. Tick Don’t show this message again and click OK. This is a one-time step.

Press F8 once more and the first .docx appears in the Word folder. Then press F5 to run the rest: in the video all ten test PDFs became ten Word files.

Part 3 – Show the Progress in the Status Bar

Step 6: Add a file counter

With hundreds of PDFs you want to see progress. Add these lines:

Application.ScreenUpdating = False
Application.DisplayStatusBar = True
...
Dim file_Count As Integer
file_Count = 0

For Each f In fo.Files

    Application.StatusBar = "Converting - " & file_Count + 1 & "/" & fo.Files.Count

    Set doc = wa.Documents.Open(f.Path)
    doc.SaveAs2 (word_path & "\" & Replace(f.Name, ".pdf", ".docx"))
    doc.Close False

    file_Count = file_Count + 1
Next

wa.Quit

Application.StatusBar = ""
MsgBox "All the files converted in word files"
  • ScreenUpdating = False stops Excel redrawing the screen; DisplayStatusBar = True keeps the status bar visible.
  • file_Count starts at 0 and goes up by one after every file. The status bar shows file_Count + 1 (the file being converted) and fo.Files.Count (the total), so it reads Converting – 1/10, Converting – 2/10 and so on.
  • Setting Application.StatusBar = "" at the end gives the status bar back to Excel, and the message box tells you the job is done.

Step 7: Assign the macro to a button

Back in Excel, insert a rounded rectangle from Insert > Shapes and type Convert PDF to Word on it. Right-click it, choose Assign Macro, set Macros in to This Workbook, pick PDF_To_Word and click OK. Empty the Word folder, click the button and watch the counter in the status bar. Save the workbook as an .xlsm file so the macro is kept.

Part 4 – Switch to Late Binding

Step 8: Remove the dependency on the Word 15.0 library

The macro above uses early binding: it declares Word.Application and needs the Word 15.0 reference. Open the file on a PC with a different Office version and you may get a missing-reference error. The fix shown in the video is late binding. Replace the two Word declarations with:

Dim wa As Object
Dim doc As Object

Set wa = CreateObject("Word.Application")
wa.Visible = True

CreateObject("Word.Application") starts whichever Word is installed, and because wa and doc are plain Objects, the Word reference is no longer needed. In the video PK unticks the Word library and it still runs. Keep Microsoft Scripting Runtime ticked, because FileSystemObject, Folder and File are still early-bound.

The Complete VBA Code

Here is the full PDF to Word converter macro as it stands at the end of the video:

Option Explicit

Sub PDF_To_Word()

Application.ScreenUpdating = False
Application.DisplayStatusBar = True

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File

Dim wa As Object
Dim doc As Object

Set wa = CreateObject("Word.Application")
wa.Visible = True

Dim pdf_path As String
Dim word_path As String

pdf_path = sh.Range("F4").Value
word_path = sh.Range("F5").Value

Set fo = fso.GetFolder(pdf_path)

Dim file_Count As Integer
file_Count = 0

For Each f In fo.Files

    Application.StatusBar = "Converting - " & file_Count + 1 & "/" & fo.Files.Count

    Set doc = wa.Documents.Open(f.Path)
    doc.SaveAs2 (word_path & "\" & Replace(f.Name, ".pdf", ".docx"))
    doc.Close False

    file_Count = file_Count + 1
Next

wa.Quit

Application.StatusBar = ""
MsgBox "All the files converted in word files"

End Sub

The version in the finished product file also sets Application.DisplayAlerts = False at the top and shows All PDF files have been converted in to word with vbInformation at the end.

Make the Loop Safer (Optional Addition)

This section is an addition to the video, based on general VBA practice. The video loop sends every file in the folder to Word. If the folder also holds a .txt file, an image or a document, the macro still opens it and saves it under its old name. This version converts only .pdf files and builds the Word file name from the base name:

Dim docName As String

For Each f In fo.Files
    If LCase(fso.GetExtensionName(f.Name)) = "pdf" Then
        file_Count = file_Count + 1
        Application.StatusBar = "Converting - " & file_Count
        docName = fso.BuildPath(word_path, fso.GetBaseName(f.Name) & ".docx")
        Set doc = wa.Documents.Open(f.Path, ConfirmConversions:=False, ReadOnly:=True)
        doc.SaveAs2 docName, 16   ' 16 = wdFormatDocumentDefault (.docx)
        doc.Close False
    End If
Next

GetExtensionName skips anything that is not a PDF, GetBaseName also handles capital .PDF (the original Replace is case-sensitive), BuildPath adds the backslash only when needed, and 16 is wdFormatDocumentDefault (.docx) written as a number so it works with late binding.

Common Errors and Fixes

Compile error: User-defined type not defined

A reference is missing. FileSystemObject, Folder and File need Microsoft Scripting Runtime; Word.Application and Word.Document need the Word Object Library. Tick them in Tools > References, or switch the Word objects to late binding as in Part 4.

Run-time error 76: Path not found

The path in F4 is wrong or the folder does not exist. Copy the path from the File Explorer address bar and paste it into the cell. Make sure the Word folder in F5 exists too, otherwise SaveAs2 fails.

Word cannot open the PDF

(Addition.) Opening PDFs as editable documents needs Word 2013 or later. Older Word versions cannot read PDF files, so late binding alone will not help on a PC that only has Word 2010. Password-protected PDFs also stop the macro.

Tips

Want It Ready-Made?

If you would rather use a finished tool than build it, the PDF to Word Converter Macro in Excel VBA on NextGenTemplates.com comes with the Settings sheet and the Start Conversion button ready to go. For data rather than documents, the PDF to Excel Converter in Excel VBA pulls PDF content into a workbook. Browse all Excel utility and converter tools for more.

Related Tutorials

Frequently Asked Questions

Can Excel VBA convert PDF files to Word?

Yes. Excel VBA starts Microsoft Word in the background, opens each PDF with Documents.Open and saves it as a .docx file with SaveAs2. Word itself does the PDF conversion, so you need no API, add-in or third-party tool, only Word 2013 or later installed on the same PC.

Which references does the PDF to Word converter need?

Microsoft Scripting Runtime for the File System Object that loops through the folder. With early binding you also tick Microsoft Word 15.0 Object Library, or 16.0 in newer Office versions. With late binding, as in the final code, the Word reference is not needed at all.

Why does Word show a message when the macro opens the first PDF?

Word warns that it will convert the PDF into an editable document and that the result may not look exactly like the original. Tick Don't show this message again and click OK once. After that the macro runs through the folder without stopping.

Will the Word file look exactly like the PDF?

Not always. Text-based PDFs with simple layouts convert well. PDFs with many graphics, columns or complex tables may shift slightly, and scanned PDFs that are only images will not give editable text. Check a few converted files before you rely on the output.

Can I buy the finished PDF to Word converter?

Yes. The ready-made PDF to Word Converter Macro in Excel VBA is available on NextGenTemplates.com, with the folder paths and the Start Conversion button already set up.

About the Author

PK is a Microsoft Excel expert and trainer and the founder of PK: An Excel Expert and NextGenTemplates.com. He has been teaching Excel, VBA, Power Query and Power BI since 2016 on his YouTube channel. New to macros? Start with his free step-by-step VBA course.

Conclusion

A PDF to Word converter macro in Excel VBA needs only one loop: the File System Object walks through the PDF folder, Word opens each file, SaveAs2 writes the .docx and the document closes. Add the status bar counter, a button and late binding, and you can convert hundreds of PDFs into editable Word files in one click on almost any Office PC. Build it once, save it as an .xlsm and reuse it whenever a folder of PDFs needs editing.

PK
Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!
https://www.pk-anexcelexpert.com