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.
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.