Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2013, 06:59 AM
Kazona Kazona is offline How to go through subdirectories in the following macro Windows 7 64bit How to go through subdirectories in the following macro Office 2013
Novice
How to go through subdirectories in the following macro
 
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
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom icon, undo/redo for macro, permanent macro Rapier Excel 0 08-05-2013 06:30 AM
How do I assign a macro to a button when the macro is in my personal workbook? foolios Excel Programming 2 07-27-2011 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft