PDA

View Full Version : Attached Template Question



ASkolnick
06-06-2012, 11:59 AM
We are using an attachedtemplate to hold our code base.

It appears attaching our template has been breaking our digital certificate.

It appears on save, the file which is attached is still holding on to that attached code.

If we release it to early (Since the code for save and the code for closing is in that base), the code would not run.

It is working OK now, but the problem is once this item is saved into a 3rd party chart and then edited, the macro security comes into play.

Any help is greatly appreciated.

Thank you.

Frosty
06-06-2012, 02:28 PM
Can you be a bit more specific? An attached template to what? A digital certificate for what? Once this item (the attached template? A document with the code base template attached?) is saved into a 3rd party chart? Where?

I can't tell what you're describing, honestly.

As a general rule, when you open a document... that document checks the attachedtemplate property. If it finds the attached template, then it loads that template into the Templates collection. Any code in that attached template is then accessible while any documents attached to that template are open in Word.

However, in some scenarios, that template will not be unloaded from the templates collection, even though the last document attached to that template has been closed.

I believe most of those scenarios revolve around custom code in the attached template relating to the document close event.

Adding in the complexity of an embedded object (and whether the OLE process has released the Winword process needed to display that embedded object) could trigger a number of macro security issues.

So, in summary... are you sure you wouldn't be better served by a global addin?

ASkolnick
06-07-2012, 06:37 AM
Thanks, Frosty. You helped me before. The code, which is in the attached template, has the save and close procedure.

Global Add-in vs. Attached Template:
We have times where more than one document will be opened simultaneously and there are global variables applicable to each individual document, so that does not work.

It was my understanding that the attached template leaves once word is closed, but it appears the attached template is still saved to the document. It had been working fine, but now it seems to be having issues.

Any ideas on when to detach if necessry would be greatly appreciated.

Frosty
06-07-2012, 06:45 AM
But you can load and unload global addins too. Even though there should be no scope issues with public variables in different addins--even if they have the same name.

I think you have a bed setup for what you're trying to accomplish. If you are attaching a template and then detaching that template... And the whole purpose is access to the code in that template while the document is open, then you are describing an addin. Attached templates are designed to persist between save/close events.

fumei
06-07-2012, 11:17 PM
"but it appears the attached template is still saved to the document"

Yes..that is why they are called attached.

fumei
06-11-2012, 12:40 PM
1. ALL documents hafve an attached template. You can not have a document that does not have an attached template.

2. Code (macros) can live in various locations. Generally speaking if there is a SCOPE issue, or an access issue, with code, having a global add-in is a good solution. One reason is that they can work across different documents (and independent of attached templates). Another is that they can be loaded dynamically, when you need them.