View Single Post
 
Old 09-09-2013, 06:59 AM
Kazona Kazona is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Sep 2013
Posts: 1
Kazona is on a distinguished road
Default How to go through subdirectories in the following macro

Hello everyone.

I have the following macro to batch change the templates of all word documents in a folder. However, there are several subdirectories within that folder as well, so I would like to have it check those as well. Can anyone modify it so that it does that?

Code:
Sub ChangeTemplates()
    Dim strDocPath As String
    Dim strTemplateB As String
    Dim strCurDoc As String
    Dim docCurDoc As Document

    ' set document folder path and template strings
    strDocPath = "C:\Users\servicedesk\Desktop\Test\"
    strTemplateB = "C:\Users\servicedesk\Desktop\Blanco.dotx"

    ' get first doc - only time need to provide file spec
    strCurDoc = Dir(strDocPath & "*.doc")

    ' ready to loop (for as long as file found)
    Do While strCurDoc <> ""
        ' open file
        Set docCurDoc = Documents.Open(FileName:=strDocPath & strCurDoc)
        ' change the template
        docCurDoc.AttachedTemplate = strTemplateB
        ' save and close
        docCurDoc.Close wdSaveChanges
        ' get next file name
        strCurDoc = Dir
    Loop
    MsgBox "Finished"
End Sub
Reply With Quote