Word Macros to Convert files from .docx to .doc -Subfolders!

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

LorieG

Thread Starter
Joined
Jan 19, 2011
Messages
1
Hello,
I am trying to figure out how to add to my current macro in order for it to go through subfolders as well. The code currently works fine but does not go deeper then the first folder. I need to it to go into all sub folders as well.

Currently it looks like this:
Sub conv()
sPath = "C:\Temp\"
sFile = Dir(sPath & "*.docx")
While sFile <> ""
With Documents.Open(sPath & sFile)
.SaveAs FileName:=sPath & Replace(sFile, "docx", "doc"), FileFormat:=0
.Close
End With
sFile = Dir
Wend
End Sub

Again i need to add to this so that it goes in and converts in sub folders as well.

Any help is extremly greatly appreciated.

-Lorie
 
Joined
Sep 4, 2003
Messages
4,912
This should do the trick

Code:
Sub conv()

Dim FSO As Object
Dim SourceFolder As Object
Dim SubFolder As Object

sPath = "C:\Temp\"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(sPath)

sFile = Dir(sPath & "*.docx")
While sFile <> ""
Documents.Open (sPath & sFile)
ActiveDocument.SaveAs FileName:=sPath & Replace(sFile, "docx", "doc"), FileFormat:=0
ActiveDocument.Close
sFile = Dir
Wend

For Each SubFolder In SourceFolder.subfolders
sPath = SubFolder & "\"
sFile = Dir(sPath & "*.docx")
While sFile <> ""
Documents.Open (sPath & sFile)
ActiveDocument.SaveAs FileName:=sPath & Replace(sFile, "docx", "doc"), FileFormat:=0
ActiveDocument.Close
sFile = Dir
Wend
Next


End Sub
Rollin
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top