1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Business Applications' started by LorieG, Jan 19, 2011.

Thread Status:
Not open for further replies.
  1. LorieG

    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
     
  2. Rollin_Again

    Rollin_Again

    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
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/975642

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice