File Path Wrong in Document Template field

C

Carol McDowell

I have a directory of saved Word 97 files. These files
were created from a workgroup template that was password
protected for forms. The workgroup templates directory
has been moved to a different server. The old directory
and server no longer exists. Therefore, when I try to
open my saved files that have a workgroup template
attached, it takes Word a long time time to open them,
because the file path to the attached template no longer
exists (Tools-Templates and Add-ins-Document Template
field has the wrong file path).

So far, I figured out that after I opened one of these
files, I could run a macro like this:

Sub RemoveReference()
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = ""
End With
End Sub

I then save the file and when I reopen it, it opens
immediately, since the old file path has been removed from
the Document Template field. However, I have about 100
files that have have the incorrect file path in the
Document Template Field. I don't want to have to open each
one to run the macro. How can a run a macro on an entire
folder of saved Word 97 files?

If this is the wrong approach, I would sincerely
appreciate being pointed in the right direction. Thank
you.
 
D

Dave Lett

Hi Carol,

You might try something like the following (which was virtually copied from
"How to read the filenames of all the files in a directory into an array" at
http://www.mvps.org/word/FAQs/MacrosVBA/ReadFilesIntoArray.htm):

Dim sFolder As String
Dim MyFile As String
Dim Counter As Long

'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

sFolder = "c:\temp\"

'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$(sFolder & "*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)


For Counter = 0 To UBound(DirectoryListArray)
Documents.Open FileName:=sFolder & DirectoryListArray(Counter)
' run your routine
Call RemoveReference
' close the document
Documents(sFolder & DirectoryListArray(Counter)).Close
SaveChanges:=wdSaveChanges
Next Counter

HTH
 
D

Doug Robbins - Word MVP

Hi Carol,

You could incorporate your procedure into the macro that you will find in
the
article "How to Find & ReplaceAll on a Batch of Documents in the Same
Folder" at:

http://www.mvps.org/word/FAQs/MacrosVBA/BatchFR.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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