Word 2007 Implementation of a Macro for a limited template set

  • Thread starter Samuel Sunsmith
  • Start date
S

Samuel Sunsmith

Situation: I have a Document_Close Macro that I want to share between a set
of templates. Conversely there is another set of templates that do not need
this macro and it would be a hinderance to the end users if it executed for
all documents, hence implementing it in Normal.dotx isn't an option. Is it
possible to "share" a macro among a limited set of templates? If so how?
Possible Solutions: Copying the macro to each of the templates is a solution
but is a maintenance nightmare when the macro changes.
Is it possible to have template A load template B so that the Document_Close
Macro will execute when the Document closes?
 
C

Cindy M.

Hi Samuel,
Situation: I have a Document_Close Macro that I want to share between a set
of templates. Conversely there is another set of templates that do not need
this macro and it would be a hinderance to the end users if it executed for
all documents, hence implementing it in Normal.dotx isn't an option. Is it
possible to "share" a macro among a limited set of templates? If so how?
Possible Solutions: Copying the macro to each of the templates is a solution
but is a maintenance nightmare when the macro changes.
Is it possible to have template A load template B so that the Document_Close
Macro will execute when the Document closes?
Two basic ways to go about this:

1. Create a template that will be loaded as a template add-in (put it in the
user's Startup folder). Put the shared code in that. In the individual
templates' Document_Close macro (the one in the ThisDocument module) call the
code in the add-in template (Application.Run method).

2. Use the Application's DocumentClose event, which means it would first for
all documents. You can then check the document's AttachedTemplate property and,
if it's a template that should use the code, branch into the shared code.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Samuel Sunsmith

Thank you I will give it a try and post the results back here later today
(Sunday, 10/5 or tomorrow Monday, 10/6)
 
S

Samuel Sunsmith

Follow up. Thank you Cindy!

I used your second solution, tying it into Normal.dotm as I have some
general tools there as well. Adding the Document_Close macro into Normal.dotm
is an excellent solution as now I have all my code in one place. Maintenance
nightmare solved.

Just a note to folks reading this in the future, as of today, the only way I
could get the macro to run in Normal.dotm was to use the syntax:

Application.Run "Module.Macro"

Which is documented in:

WD2000: Run Time Error 4366 Using Application.Run Command
http://support.microsoft.com/kb/198840
 
S

Samuel Sunsmith

Point of clarity for future readers.

In each of the templates where I wanted the "Document_Close" event to
run the Macro in Normal.dotm I added:

Application.Run "Module.Macro"

to the event code.
 
C

Cindy M.

Hi Samuel,
I used your second solution, tying it into Normal.dotm as I have some
general tools there as well. Adding the Document_Close macro into Normal.dotm
is an excellent solution as now I have all my code in one place. Maintenance
nightmare solved.
Glad things are working - so far.

If I were you I would *not* keep all the code in Normal.dot. I would rather put
it in a template saved in the Startup folder, which will be loaded as a Template
Add-in. These are less prone to becoming damaged (and thus lost) than
Normal.dot.

If you do keep it in Normal.dot, be sure to make a file back-up whenver you
change the code so that you don't end up losing it!

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Samuel Sunsmith

I understand. I have a user group that is not very technical I'm trying the
make the
process as painless as possible for them and the least maintenance hassle
for me.
I do back up my own environment frequently, and the master copy of the
Normal.dotm is kept on a network drive so if their copy is lost. But it never
hurts
to be reminded. Thanks!
 

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