Using DocumentBeforeSave on special templates

M

Mads W.

I want to use the DocumentBeforeSave application event on documents created
via special templates. I have read the article on the subject on
word.mvps.org (http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm),
quite a good article. But it seems that the example in that article will
trigger with every document, not just when using special templates.

So how do I use the DocumentBeforeSave on special templates only?

One thing that's equal to all templates I want to trigger my code on, is
that I will have a bookmark called "Firm2" in the document generated from
the template.

Mads W.
 
J

Jean-Guy Marcil

Mads W. was telling us:
Mads W. nous racontait que :
I want to use the DocumentBeforeSave application event on documents
created via special templates. I have read the article on the subject
on word.mvps.org
(http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm), quite a
good article. But it seems that the example in that article will
trigger with every document, not just when using special templates.
So how do I use the DocumentBeforeSave on special templates only?

One thing that's equal to all templates I want to trigger my code on,
is that I will have a bookmark called "Firm2" in the document
generated from the template.

At the top of the code in the event module, include something like:

If Not AttachedTemplate.Name = "MyTemplate.dot" Then Exit Sub

Thus should do the trick, no?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Mads W.

Hi Jean-Guy Marcil,

Thx for your answer. I apologise for my late respons on this thread.
I finally got the code working, but with a little twist - it always takes a
little twist doesn't it. :)
I put my code in the different templates that I merge into. I use the
autonew trigger to initiate my little class.
Then I was able to use the trigger DocumentBeforeSave.

- Thx

Mads W.
 

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