batch template application

C

Cagdas Ozgenc

Hi,

How can I apply a template to a bunch of word files as a batch process
without individually opening each document and applying the template?

Thanks
 
M

Mark Tangard

Hi Cagdas,

I'll bet you're an HTML person.

Short answer: You can't do that, at least not in Word versions
thru 2002).

But you could use a macro to open a whole folder full of Word
docs and attach a template to each. (In Word it's *attach*,
not "apply.") Something like this:

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

Note that while this capability is deemed convenient for web
designers, it typically scares the crap out of Word users,
who ordinarily uncheck the 'Update Styles on Open' box after
the first import. If you are, or might evolve into, one of
those folks, you'll want to add code that opens the docs
again, makes that property false and resaves.
 
C

Cagdas Ozgenc

Mark Tangard said:
Hi Cagdas,

I'll bet you're an HTML person.

No, I am an XML person.
Short answer: You can't do that, at least not in Word versions
thru 2002).

But you could use a macro to open a whole folder full of Word
docs and attach a template to each. (In Word it's *attach*,
not "apply.") Something like this:

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

Note that while this capability is deemed convenient for web
designers, it typically scares the crap out of Word users,
who ordinarily uncheck the 'Update Styles on Open' box after
the first import. If you are, or might evolve into, one of
those folks, you'll want to add code that opens the docs
again, makes that property false and resaves.

Thanks that was very helpful.
 

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