Last active
January 26, 2022 15:00
-
-
Save sprestridge/72afd509a15bd87b776e5e47f9af600e to your computer and use it in GitHub Desktop.
Convert Microsoft Word `.doc` files to Word `.docx` files with VBA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub WordDocIntoDocx() | |
' convert Word .doc files to Word .docx | |
' Organize all files to be processed in one directory. | |
' Open Word and press “Alt+ F11” to open the VBA editor. | |
' Click “Normal” project and click “Insert” after it. | |
' Choose “Module” to insert a new module in the project. | |
' Paste the Code, update the file path (strFolder variable), and Run the code. | |
Dim objWordApplication As New Word.Application | |
Dim objWordDocument As Word.Document | |
Dim strFile As String | |
Dim strFolder As String | |
'set to correct directory | |
strFolder = "C:\DocIntoDocx\" | |
strFile = Dir(strFolder & "*.doc", vbNormal) | |
While strFile <> "" | |
With objWordApplication | |
Set objWordDocument = .Documents.Open(FileName:=strFolder & strFile, AddToRecentFiles:=False, ReadOnly:=True, Visible:=False) | |
With objWordDocument | |
.SaveAs FileName:=strFolder & Replace(strFile, "doc", "docx"), FileFormat:=16 | |
.Close | |
End With | |
End With | |
strFile = Dir() | |
Wend | |
Set objWordDocument = Nothing | |
Set objWordApplication = Nothing | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment