Only execute Macro if Doc Template is XX or YY

T

Trev Maxwell

I am automating an update of 1,000s of documents in multiple directories,
but only want the Update code inside the macro to run the code if the
Document is based on a specific template, but I cannot figure out how to do
this. Any suggestions.

Many Thanks

Trev
 
J

Jonathan West

Trev Maxwell said:
I am automating an update of 1,000s of documents in multiple directories,
but only want the Update code inside the macro to run the code if the
Document is based on a specific template, but I cannot figure out how to do
this. Any suggestions.

Many Thanks

Trev

After opening the document, you can look at the Name or FullName property of
the AttachedTemplate property of the document.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
T

Trev Maxwell

Jonathan, Works so far, but I was surprised to find the Template Name
attribute was case sensitive. One other problem I have come accross today.
Because I am having to toggle field codes (object being to change from Date
to Createdate), templates which have 'Fillin' fields require me to respond
to the boxes, so I am having to sit there monitoring progress - OK when
testing, but would not like to be doing it for 20 thousand + documents.
Any way I can tell the macro to respond with either an OK or ignore?

Many thanks

Trev
 
J

Jonathan West

Trev Maxwell said:
Jonathan, Works so far, but I was surprised to find the Template Name
attribute was case sensitive. One other problem I have come accross
today. Because I am having to toggle field codes (object being to change
from Date to Createdate), templates which have 'Fillin' fields require me
to respond to the boxes, so I am having to sit there monitoring progress -
OK when testing, but would not like to be doing it for 20 thousand +
documents. Any way I can tell the macro to respond with either an OK or
ignore?

Setting Application.DisplayAlerts = wdAlertsNone might help

But you don't have to toggle field codes to change the fields. You can cycle
through the Fields collection of each document like this

Dim oField as Field
For Each oField in ActiveDocument.Fields
If Left$(oField.Code.Text, 5) = " DATE" Then
oField.Code.Text = " CREATEDATE" & Mid$(oField.Code.Text, 6)
End If
Next oField


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
T

Trev Maxwell

Johathan
Thank you again. Will try both parts of your solution. Many thanks for the
tips.

Trev
 

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