Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macros not saved with Protected Word Doc 1

Status
Not open for further replies.

pozitron969

Programmer
May 14, 2002
29
0
0
US
Hello all,

I have created a Word 2003 doc template that uses tables to organize Form elements. I have a series of macros that are used to add rows to the tables and insert or delete various form elements. The macros are executed by the MacroButton Field. The macros will automatically unprotect the doc and then re-protect the doc again once it is done. Ideally I would like the document to be protected all the time, execpt when a macro is executing.

The problem I am running into is that if the template is saved it doesn't keep the macros with the template. This also happens when I fill out the form and save it as a document. The macros will need to be available for further edits to the document.

By default my Macro setting is set to medium. I have also tested this scenario with it on Low.

I am able to import the .bas file from an older version of the template and get the macros to work, but importing them every time is not a solution I would like.

Any help would be greatly appreciated. Thank you.

Pozitron969
 
Where are your macros stored in the template? I threw something together with a macrobutton field and the referenced macro in a standard code module. A new document created from this template activated the macro as expected.

Regards,
Mike
 
Hi,

Thank you for your response.

While I was originally creating the template I always stored them in the Document itself, not the Normal.dot. I have also tried importing the .bas file into the Project(OpsRunDoc_Template) project in the VBA Project Explorer. The template filename is OpsRunDoc_Template.dot They will show up and I can use them, but once I save the file they are gone.

Could this be an issue with having Protect Document turned on?

Pozitron969
 
No, I don't think so. I kept doc protection (protected for Forms) on and the macro still fired. However, once a document was created based on the template, saved, closed then opened without the template file being available (I changed the extension), the macro no longer worked; no error or other message. Investigating further: With my template-base document open after creation, there is a reference to the template (in the VBE Project Explorer) and the VB Project that makes up the template, including the code module, appears loaded (is listed in the treeview). After closing the doc then re-opening with the template file "disabled", the reference is to normal.dot, not the template. So, is there some way the template has been disconnected from the document? A long shot I know, but based on my findings, it would account for the behavior.

Mike
 
Thank you! Well, it looks like you are right. I renamed the template to a new name and extension. I opened an example of the document that I created and the macros were gone.

This template is posted to our developers on our intranet site, so more than likely the template and the resulting document will be in a different location. This sounds like a problem that will persist.

Does anyone know of a way to force the documents created from the template to include the code instead of reference it?

Ideally, I would really like to keep using a template for the basis of our documentation. The other alternative I am considering is to place the template on our intranet site as a standard Word document, instead of a template. If this would preserve the macros in each copy of the document then I would prefer that over using a template. Does anyone have any other suggestions?
 
Do you (your company) have a shared network drive where the template file could be stored? As long as the template wasn't moved, this should work.


Mike
 
Yes, we have a mapped drive location where the doc template is stored and the template is also stored on the intranet site.

ie: P:\doc\templates\opsrundoc_template.dot

So as long as the template is always located in the path above any docs that were created from the template should always use the reference, correct?

Will this scenario work if the developers retrieve the template from the intranet site? The intranet site will have an exact copy of the template, but it will still be stored on a completely different machine. We originally noticed this problem when the developers retrieved the template file from the intranet site, created documents from it on their local machine then stored them on the network share. I guess some where along the way the reference must have been broken.

Thanks again, I really appreciate your help with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top