Attaching Template to Documents

  • Thread starter Thread starter Ross Payne
  • Start date Start date
R

Ross Payne

In Word 2003, I have 30 documents in one folder, all of which I would like
to attach to normal.dot and update styles. Is there a way to do this to all
30 at once, or must I do them one by one? Thanks,


Ross Payne
 
Hi Ross,

Try this (note: untested code):

Dim i As Long, d As Document
With Application.FileSearch
.NewSearch
.LookIn = "C:\Path\FolderName" '<-- your path
.SearchSubFolders = False
.FileName = "*.DOC"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Set d = Documents.Open(FileName:=.FoundFiles(i))
d.AttachedTemplate = NormalTemplate
d.UpdateStylesOnOpen = True
d.Close -1
Set d = Documents.Open(FileName:=.FoundFiles(i))
d.UpdateStylesOnOpen = False
d.Close -1
Next i
Else
MsgBox "No matching files found."
End If
End With
MsgBox "Done."

The doc is opened a second time to uncheck UpdateStylesOnOpen because if
that option remains enabled, the document's styles will be updated each
time the document is opened, which is rarely what's desired.
 
Back
Top