change macro to include subfolders

J

Jim

Hi,

We have an issue with word whereby the server that held all the templates
and docs needed replacing, the new server (which has a different name to the
old one) works fine apart from one thing - whenever we open a word doc that
has a template set in the tools/templates and addins option it takes up to 5
minutes to open. We needed a way to change the template in the doc
automatically and set it to normal.dot. I found this Knowledgebase article
830561 that has this macro in it:

Sub Test()
Dim strFilePath As String

Dim strPath As String

Dim intCounter As Integer

Dim strFileName As String

Dim OldServer As String

Dim objDoc As Document

Dim objTemplate As Template

Dim dlgTemplate As Dialog

Dim nServer As Integer

'hardcode the name of the old server.

OldServer = "{enter the name of the Old Server}"

nServer = Len(OldServer)

strFilePath = InputBox("What is the folder location that you want to
use?")

If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\"

strFileName = Dir(strFilePath & "*.doc")

Do While strFileName <> ""

Set objDoc = Documents.Open(strFilePath & strFileName)

Set objTemplate = objDoc.AttachedTemplate

Set dlgTemplate = Dialogs(wdDialogToolsTemplates)

strPath = dlgTemplate.Template

If LCase(Left(strPath, nServer)) = LCase(OldServer) Then

objDoc.AttachedTemplate = NormalTemplate

End If

strFileName = Dir()

objDoc.Save

objDoc.Close

Loop

Set objDoc = Nothing

Set objTemplate = Nothing

Set dlgTemplate = Nothing

End Sub
The above macro does what we need it to apart from one thing - we need it to
automatically go through all subfolders as well as we have hundreds of word
docs with this issue, how can I change the above macro to include sub
folders?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top