Skip to content

Instantly share code, notes, and snippets.

@lizardking8610
Last active December 5, 2024 16:51
Show Gist options
  • Save lizardking8610/33d47a50da3eb0dbf80248e093288a8c to your computer and use it in GitHub Desktop.
Save lizardking8610/33d47a50da3eb0dbf80248e093288a8c to your computer and use it in GitHub Desktop.
Batch Convert Doc to Docx with VBA and Vice Versa and Doc to PDF Batch
Sub TranslateDocIntoDocx()
Dim objWordApplication As New Word.Application
Dim objWordDocument As Word.Document
Dim strFile As String
Dim strFolder As String
strFolder = "E:\Temp\"
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
Sub TranslateDocIntoDocx()
Dim objWordApplication As New Word.Application
Dim objWordDocument As Word.Document
Dim strFile As String
Dim strFolder As String
strFolder = "C:\Users\Computer\Documents\pdfs\"
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", "pdf"), FileFormat:=17
.Close
End With
End With
strFile = Dir()
Wend
Set objWordDocument = Nothing
Set objWordApplication = Nothing
End Sub
Sub TranslateDocxIntoDoc()
Dim objWordApplication As New Word.Application
Dim objWordDocument As Word.Document
Dim strFile As String
Dim strFolder As String
strFolder = "E:\Temp\"
strFile = Dir(strFolder & "*.docx", 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, "docx", "doc"), FileFormat:=0
.Close
End With
End With
strFile = Dir()
Wend
Set objWordDocument = Nothing
Set objWordApplication = Nothing
End Sub
@lizardking8610
Copy link
Author

lizardking8610 commented Jun 29, 2017

Batch Convert Word Doc to Docx Files
First and foremost, organize all file to be processed in one file folder.
Then open Word and press “Alt+ F11” to open the VBA editor.
Now click “Normal” project and click “Insert” after it.
Next choose “Module” to insert a new module in the project.
Paste the Code and Run it

Batch Convert Word Docx Files to Doc Files
To start off, place all docx files in one file folder.
Similarly, press “Alt+ F11” to open VBA editor.
Then follow the same way in method 1 to insert a new module and open it.
Next paste the code

Filetype is 17 for PDF and a huge shoutout to Vera for hooking this up [https://www.datanumen.com/blogs/3-quick-ways-to-batch-convert-word-doc-to-docx-files-and-vice-versa/]

@erenyenigul
Copy link

Should the procedure be the same on Mac? I've tried this on Mac, and With objWordApplication line gives me a random error.

@Totorodesu
Copy link

Thanks for posting this - I'll try this out shortly. I know practically zero about coding but when I use the internal converter in Word I seem to have to resave with compatibility mode turned off to insert new themes. Is there a way of adding the option CompatibilityMode into the code above so it set to wdCurrent 65535 so that it'll be the latest version of Word so i can just insert the Font and Colour themes?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment