automatically copy macros from template to document

T

TheRoundPen

Hello,

I have read every post on this subject and found one from 2006 that was
exactly my situation, however the response does not work since the template
is a protected document.

I have an employee evaluation template that has been distributed to all
leaders at all of our properties. I have read the warnings about including
the macros in the document that is created from the template, but this is
abolutely what I need to do. I have tried recording a macro the uses the
organizer to copy macros to another file, but I get an error message that
says I cannot attach a protected template. Unprotecting the template is not
an option, as that is what makes the evaulation work to begin with. Is there
a way to do this programmatically and automatically when the document either
open or closes?

I REALLY appreciate any light you can shed on this subject!

Carla McDonald
 
G

Graham Mayor

You cannot perform actions on a protected form that require the form to be
unprotected in order to do, so without first unprotecting the form.
If all of your staff who will be using the template have the template
containing the macros, then why do the macros need to be copied to the
documents? Documents created from the templates will use the macros in the
templates.Once the doument is created, the macros should be redundant - and
if they are not, then they will still refer back to the template for their
further use should the document require more editing.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Gordon Bentley-Mix on news.microsoft.com

Further to what Graham has said: If you're using code to copy the macros from
the template to the document, I can see no reason why you cannot include code
to unprotect and re-protect the template as part of this process. I've done
this in several instances.

In one case, I have "master" template that is used to create customised
templates for individual clients. This template creates a copy of itself,
unprotects the copy and writes info into it, and then re-protects the copy.

In another case, I have a process that allows users to set certain values
selected in a UserForm as the "default", which are saved in document
variables in the template. This process also unprotects the template, writes
the values into the variables, and the re-protects the template.

In a final case, I have "automated version control" on several templates,
which is executed from an AutoOpen macro. This process also writes
information into document variables, as well as updating a field in the
footer. Again, the code unprotects the template, writes the info into it, and
then re-protects the template.

In all cases, it's a simple matter of using the .Unprotect and .Protect
methods (with the appropriate arguments) to make the protected template
available for the intended purpose and then locking it down again. The
hardest part of the whole thing - especially in the case of setting the
"default" UserForm values - is identifying the template, but you've obviously
got this susses since you're trying to use the Organizer to copy the macros
from the template into the document.

Of course, as Graham rightly points out, if the template is available to the
users, then there's really no need to copy the macros into the document in
the first place. Any other approach leads down the path to trouble...
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 

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