Hi Peter
Let me get this straight: You writing code in a .dot file. You want to add a
command bar to that .dot file. Right?
Then what you need is
CustomizationContext = ThisDocument
If you use
CustomizationContext = ActiveDocument
then the changes will be made to the active document, if there is one, which
could be anything. And your users won't thank you for sprinkling toolbars
and buttons on their documents.
Don't forget that, having made a change to ThisDocument (by storing
commandbars in it), you'll need to mark it as saved, or the user will get
"do you want to save?" messages. Do that with:
ThisDocument.Saved = True
>CustomizationContext = NormalTemplate
Don't do that. That is, don't attempt to re-set it.
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
> Hi Russ
>
[quoted text clipped - 67 lines]
>> >>
>> >> Thanks for taking the time to read this + Cheers - Peter.
Tont - 30 Sep 2007 12:38 GMT
Hi Shauna
The code is in an AddIn that's specifically designed to add a menubar to
templates. If you set:
CustomizationContext = ThisDocument
the menubar gets added to the AddIn and not the template (aka the
ActiveDocument).
The Addin specifically checks the ActiveDocument.Type property to determine
that the ActiveDocument is in fact a template before instantiating the Form
that drives this process.
And yes, since I'm adding a toolbar to the ActiveDocument the
CustomizationContext must be restored, or else two potential problems arise.
The first is any code that tries to make any menu/toolbar/key binding changes
without setting the CustomizationContext will affect the template I assigned
to it rather than Normal.dot (this of course being the default
CustomizationContext). The second is that if the user closes the template
the CustomizationContext is assigned to, and some other code then tries to
query (rather than assign to) the CustomizationContext object you'll get an
error!
Say an AddIn adds a temporary toolbar to itself, you still need to restore
the CustomizationContext for the above two reasons. However, with an AddIn
the second problem only manifests itself if the AddIn is unload before Word
exits and some code then tries to query the CustomizationContext object
before assigning to it. In other words you wont see this one very often.
You should always restore the CustomizationContext otherwise strange and
nasty things can happen. I tend to restore to the NormalTemplate so if some
badly written user code tries to subsequently modify something it's not one
of my AddIns or templates!
Sorry, it not easy to be both accurate and succinct, so I hope I've
explained myself adequately on this.
Many thanks for your thoughts on this one, it's much appreciated - all the
best - Peter.
> Hi Peter
>
[quoted text clipped - 94 lines]
> >> >>
> >> >> Thanks for taking the time to read this + Cheers - Peter.