Skip to Content
Batch Convert .doc Format Files to .docx Using VBA Code

Batch Convert .doc Format Files to .docx Using VBA Code

Step-by-Step Guide

In this section, we’ll show you how to use VBA code to batch convert .doc files to .docx files in a specific folder. Just follow the steps below:

Step 1

Gather all the .doc files that you want to convert into a single folder.

Step 2

Open Microsoft Word, and press Alt + F11 to open the Microsoft Visual Basic for Applications (VBA) window.

Step 3

In the VBA window, click Insert > Module. Then, copy and paste the following VBA code into the module:

Sub ConvertDocToDocx() 'Updated by ExtendOffice 20181128 Dim xDlg As FileDialog Dim xFolder As Variant Dim xFileName As String Application.ScreenUpdating = False Set xDlg = Application.FileDialog(msoFileDialogFolderPicker) If xDlg.Show <> -1 Then Exit Sub xFolder = xDlg.SelectedItems(1) + "\" xFileName = Dir(xFolder & "*.doc", vbNormal) While xFileName <> "" Documents.Open FileName:=xFolder & xFileName, _ ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _ wdOpenFormatAuto, XMLTransform:="" ActiveDocument.SaveAs xFolder & Replace(xFileName, "doc", "docx"), wdFormatDocumentDefault ActiveDocument.Close xFileName = Dir() Wend Application.ScreenUpdating = True End Sub

VBA Code

Step 4

Press the F5 key to run the code. In the window that appears, select the folder containing your .doc files and click OK. The script will automatically convert all .doc files to .docx format.

Select Folder

Resources

  1. Batch Convert DOC to DOCX with VBA – ExtendOffice
Last updated on