Template location change problem.

A

anon

I need to be able to sweep a directory and its subfolders for MSWord
documents, run a macro which removes embeded document template information
and saves the document again.

This has become an issue because UNC paths have been used in the Document
Template path on many documents, and the server which they point to has been
taken offline. This causes Word to take 5-10 minutes to open the document.
Quick fix is to match an existing IP address in WINS with the UNC path name,
this speeds the opening of the documents.

I have found this code while attempting to resolve the problem :

Sub attach()
' upath = the folder we're going through
upath = "\\myserver\docs"

Application.ScreenUpdating = False
Set udoc = CreateObject("scripting.FileSystemObject")
Set getudocs = udoc.getfolder(upath)
Set unddocs = getudocs.Files

For Each fdocs In unddocs
' call to the macro that changes the templates
attachUND
ActiveDocument.Close savechanges:=wdSaveChanges
Next fdocs
End Sub
Sub attachUND()

tName = ActiveDocument.AttachedTemplate.FullName ' the old template name
If tName = ActiveDocument.AttachedTemplate.Path & "\" & "Normal.dot" Then
tName = "old template not found"
Templ = "\\myserver\templates\LeterHead.dot"
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = Templ
End With
End Sub

I have run this code on several machines but the same thing happens the
document closes and no updates appear to have been done.

Your thoughts on this problem are greatfully recieved.
 
J

Jay Freedman

I'm not sure this is the problem, but you may have to make Word "think" the
document is dirty and needs to be saved, even with the use of the
SaveChanges argument in the Close method.

Try adding this just before the Close call:

ActiveDocument.Saved = False
 

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