Answered by:
Quickly convert .docx files in a folder to .dotx format

Question
-
I need help with converting docx files in a folder to dotx. I don't really want to have to open each file individually as I have too many and it would take too long. I was thinking either using a macro, visual basic or batch file. I am using Office 2016 and Windows 10. I am an intermediate to advance user. Any advice or direction would really be appreciated.
Thursday, April 7, 2016 10:12 AM
Answers
-
You could use a macro like:
Sub DOCX_To_DOTX()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
wdDoc.SaveAs2 FileName:=strFolder & "\" & Split(strFile, ".docx")(0) & ".dotx", Fileformat:=wdFormatXMLTemplate, AddToRecentFiles:=False
wdDoc.Close
'Kill strFolder & "\" & strFile
DoEvents
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End FunctionThere's a commented-out line to delete the converted docx files, too, if you wish.
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
Cheers
Paul Edstein
[MS MVP - Word]- Edited by macropodMVP Thursday, April 7, 2016 11:36 AM
- Proposed as answer by Charles Kenyon Thursday, April 7, 2016 12:49 PM
- Marked as answer by Steve Fan Friday, April 15, 2016 8:12 AM
Thursday, April 7, 2016 11:36 AM
All replies
-
How many is too many?
A batch file will not do it because there is more to the change than the filename extension.
Any macro is going to open and save as for each file.
Here are directions for a macro that does a find and replace on each file in a given directory. It could be modified to open and save as.
How to Find & ReplaceAll on a batch of documents in the same folder
My recommendation would be to create a new folder/directory to save the new files in. I would not have the macro delete the old files.
Charles Kenyon Madison, WI
- Edited by Charles Kenyon Thursday, April 7, 2016 11:30 AM
Thursday, April 7, 2016 11:28 AM -
You could use a macro like:
Sub DOCX_To_DOTX()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
wdDoc.SaveAs2 FileName:=strFolder & "\" & Split(strFile, ".docx")(0) & ".dotx", Fileformat:=wdFormatXMLTemplate, AddToRecentFiles:=False
wdDoc.Close
'Kill strFolder & "\" & strFile
DoEvents
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End FunctionThere's a commented-out line to delete the converted docx files, too, if you wish.
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
Cheers
Paul Edstein
[MS MVP - Word]- Edited by macropodMVP Thursday, April 7, 2016 11:36 AM
- Proposed as answer by Charles Kenyon Thursday, April 7, 2016 12:49 PM
- Marked as answer by Steve Fan Friday, April 15, 2016 8:12 AM
Thursday, April 7, 2016 11:36 AM