PDA

View Full Version : Global Template and Attached Template Question



ASkolnick
06-23-2011, 11:29 AM
1) Can you have Word check for the addition of a Global template after the fact? I know the answer is probably not.

2) How do you run a macro from an attached template? Is this possible?

Any help is greatly appreciated. Thanks.

Frosty
06-23-2011, 12:48 PM
Hi there... looks like you're investigating this route. I'm like a bad penny ;)

The addins collection will show you what you're looking for.

Sub AddinsTester()
Dim sName As String
Dim oAddin As AddIn

For Each oAddin In AddIns
sName = oAddin.Name
Debug.Print sName & " Installed: " & oAddin.Installed & " Location: " & oAddin.Path
Next

sName = ActiveDocument.AttachedTemplate
Debug.Print "Attached Template: " & sName
End Sub

This should give you a guide on what kind of info you can get.

As for after the fact-- you have to tell us what fact you mean.

The addins list (and whether something is loaded/installed) is the same info you get from the Templates & Addins dialog (depending on what version of Word, you get here differently), and if something is checked-- it shows up as loaded.

The difference between a global addin and an attached template is one of context. The macros in a loaded Global addin will be available no matter what your active document is during your word session. The macros in an attached template will only be available to the activedocument of that attached template.

I think you want to look into Application.Addins.Add

The use of Application.Run will allow you access to any macros in a global addin, although it will screw up error trapping (the error object isn't passed back and forth when you use Application.Run... so you need to make sure you have error trapping in both the calling and called routines).

Someone else may have some more insight.

ASkolnick
06-23-2011, 01:06 PM
I will take all the money I can get, even if it is a bad penny.

Yes, I am investigating this route. The fact that it screws up error trapping explains also why my code worked, but it returned an error message anyway.

As for the attached template, I can get the template to attach, but it is then calling a macro to that attached template. Application.Run does not seem to work or I am calling it the wrong way. But you have given more food for thought. Thank you.

Frosty
06-23-2011, 01:19 PM
Grin.

I've found it useful in the past to use Err.Clear at the very end of a routine I knew was going to be regularly called by Application.Run.

Also, the following may help (believe it or not)
WordBasic.disableautomacros 1 '(turns automacros off)
WordBasic.disableautomacros 0'(turns them back on)