Discussion:
Missing Custom CommandBar
(too old to reply)
Tont
2007-09-28 16:59:00 UTC
Permalink
Hi All

I'm building an AddIn that adds a CommandBar and buttons to the current
document (actually it's a template). To attach the CommandBar to the current
document rather than the Normal template I'm obviously setting the
CustomizationContext. To do this I use:
CustomizationContext = ActiveDocument

The code then does its thing and builds the CommandBar. I then restore the
CustomizationContext:

CustomizationContext = NormalTemplate

Now this is where the fun begins, at this point the CommandBar is not
visible. And yes its Visible property has been set to True. The CommandBar
remains invisible until until you either:
- Switch to another Word document (assuming you have one open! - but not
another application window).
- Use Tools>Customize (you don't need to do anything, just click on the
"Close" button".
- Close and reopen the document.

I've tried all kinds of kludges - but no luck so far.

If anyone has run into this problem or can offer any insights I'd really
appreciate any help you can offer.

Thanks for taking the time to read this + Cheers - Peter.
Tont
2007-09-29 12:02:00 UTC
Permalink
Hi All

For anyone that may be interested I implemented a typical Word kludge:

' For some reason the new CommandBar is not displayed so here's the
workaround
SendKeys "{Esc}"
Application.Dialogs(wdDialogToolsCustomize).Display

If anyone really knows what's going on a real answer would be appreciated.

Cheers + good fortune to all - Peter
Post by Tont
Hi All
I'm building an AddIn that adds a CommandBar and buttons to the current
document (actually it's a template). To attach the CommandBar to the current
document rather than the Normal template I'm obviously setting the
CustomizationContext = ActiveDocument
The code then does its thing and builds the CommandBar. I then restore the
CustomizationContext = NormalTemplate
Now this is where the fun begins, at this point the CommandBar is not
visible. And yes its Visible property has been set to True. The CommandBar
- Switch to another Word document (assuming you have one open! - but not
another application window).
- Use Tools>Customize (you don't need to do anything, just click on the
"Close" button".
- Close and reopen the document.
I've tried all kinds of kludges - but no luck so far.
If anyone has run into this problem or can offer any insights I'd really
appreciate any help you can offer.
Thanks for taking the time to read this + Cheers - Peter.
Russ
2007-09-29 23:31:30 UTC
Permalink
Tont,
The screen probably needs to be forced to redraw its graphics.
Have you checked out the VBA property or method?
.ScreenUpdating
.ScreenRefresh

If those don't work, does minimizing and restoring the window work?
Post by Tont
Hi All
' For some reason the new CommandBar is not displayed so here's the
workaround
SendKeys "{Esc}"
Application.Dialogs(wdDialogToolsCustomize).Display
If anyone really knows what's going on a real answer would be appreciated.
Cheers + good fortune to all - Peter
Post by Tont
Hi All
I'm building an AddIn that adds a CommandBar and buttons to the current
document (actually it's a template). To attach the CommandBar to the current
document rather than the Normal template I'm obviously setting the
CustomizationContext = ActiveDocument
The code then does its thing and builds the CommandBar. I then restore the
CustomizationContext = NormalTemplate
Now this is where the fun begins, at this point the CommandBar is not
visible. And yes its Visible property has been set to True. The CommandBar
- Switch to another Word document (assuming you have one open! - but not
another application window).
- Use Tools>Customize (you don't need to do anything, just click on the
"Close" button".
- Close and reopen the document.
I've tried all kinds of kludges - but no luck so far.
If anyone has run into this problem or can offer any insights I'd really
appreciate any help you can offer.
Thanks for taking the time to read this + Cheers - Peter.
--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
Tont
2007-09-30 02:40:01 UTC
Permalink
Hi Russ

Thanks for the suggestion, but that did not work either. It was one of the
earlier things I tried - as a "just in case". ScreenRefresh redraws the
document but not the CommandBars.

You can sometimes get away with toggling the Visible property (causing a
redraw), but that did nothing in this case either.

Thanks for your idea anyway - it's much appreciated.

Cheers - Peter
Post by Russ
Tont,
The screen probably needs to be forced to redraw its graphics.
Have you checked out the VBA property or method?
..ScreenUpdating
..ScreenRefresh
If those don't work, does minimizing and restoring the window work?
Post by Tont
Hi All
' For some reason the new CommandBar is not displayed so here's the
workaround
SendKeys "{Esc}"
Application.Dialogs(wdDialogToolsCustomize).Display
If anyone really knows what's going on a real answer would be appreciated.
Cheers + good fortune to all - Peter
Post by Tont
Hi All
I'm building an AddIn that adds a CommandBar and buttons to the current
document (actually it's a template). To attach the CommandBar to the current
document rather than the Normal template I'm obviously setting the
CustomizationContext = ActiveDocument
The code then does its thing and builds the CommandBar. I then restore the
CustomizationContext = NormalTemplate
Now this is where the fun begins, at this point the CommandBar is not
visible. And yes its Visible property has been set to True. The CommandBar
- Switch to another Word document (assuming you have one open! - but not
another application window).
- Use Tools>Customize (you don't need to do anything, just click on the
"Close" button".
- Close and reopen the document.
I've tried all kinds of kludges - but no luck so far.
If anyone has run into this problem or can offer any insights I'd really
appreciate any help you can offer.
Thanks for taking the time to read this + Cheers - Peter.
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Shauna Kelly
2007-09-30 03:10:29 UTC
Permalink
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
Post by Tont
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
Post by Tont
Hi Russ
Thanks for the suggestion, but that did not work either. It was one of the
earlier things I tried - as a "just in case". ScreenRefresh redraws the
document but not the CommandBars.
You can sometimes get away with toggling the Visible property (causing a
redraw), but that did nothing in this case either.
Thanks for your idea anyway - it's much appreciated.
Cheers - Peter
Post by Russ
Tont,
The screen probably needs to be forced to redraw its graphics.
Have you checked out the VBA property or method?
..ScreenUpdating
..ScreenRefresh
If those don't work, does minimizing and restoring the window work?
Post by Tont
Hi All
' For some reason the new CommandBar is not displayed so here's the
workaround
SendKeys "{Esc}"
Application.Dialogs(wdDialogToolsCustomize).Display
If anyone really knows what's going on a real answer would be appreciated.
Cheers + good fortune to all - Peter
Post by Tont
Hi All
I'm building an AddIn that adds a CommandBar and buttons to the current
document (actually it's a template). To attach the CommandBar to the current
document rather than the Normal template I'm obviously setting the
CustomizationContext = ActiveDocument
The code then does its thing and builds the CommandBar. I then restore the
CustomizationContext = NormalTemplate
Now this is where the fun begins, at this point the CommandBar is not
visible. And yes its Visible property has been set to True. The CommandBar
- Switch to another Word document (assuming you have one open! - but not
another application window).
- Use Tools>Customize (you don't need to do anything, just click on the
"Close" button".
- Close and reopen the document.
I've tried all kinds of kludges - but no luck so far.
If anyone has run into this problem or can offer any insights I'd really
appreciate any help you can offer.
Thanks for taking the time to read this + Cheers - Peter.
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Tont
2007-09-30 11:38:00 UTC
Permalink
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.
Post by Shauna Kelly
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
ThisDocument.Saved = True
Post by Tont
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
Post by Tont
Hi Russ
Thanks for the suggestion, but that did not work either. It was one of the
earlier things I tried - as a "just in case". ScreenRefresh redraws the
document but not the CommandBars.
You can sometimes get away with toggling the Visible property (causing a
redraw), but that did nothing in this case either.
Thanks for your idea anyway - it's much appreciated.
Cheers - Peter
Post by Russ
Tont,
The screen probably needs to be forced to redraw its graphics.
Have you checked out the VBA property or method?
..ScreenUpdating
..ScreenRefresh
If those don't work, does minimizing and restoring the window work?
Post by Tont
Hi All
' For some reason the new CommandBar is not displayed so here's the
workaround
SendKeys "{Esc}"
Application.Dialogs(wdDialogToolsCustomize).Display
If anyone really knows what's going on a real answer would be appreciated.
Cheers + good fortune to all - Peter
Post by Tont
Hi All
I'm building an AddIn that adds a CommandBar and buttons to the current
document (actually it's a template). To attach the CommandBar to the current
document rather than the Normal template I'm obviously setting the
CustomizationContext = ActiveDocument
The code then does its thing and builds the CommandBar. I then restore the
CustomizationContext = NormalTemplate
Now this is where the fun begins, at this point the CommandBar is not
visible. And yes its Visible property has been set to True. The CommandBar
- Switch to another Word document (assuming you have one open! - but not
another application window).
- Use Tools>Customize (you don't need to do anything, just click on the
"Close" button".
- Close and reopen the document.
I've tried all kinds of kludges - but no luck so far.
If anyone has run into this problem or can offer any insights I'd really
appreciate any help you can offer.
Thanks for taking the time to read this + Cheers - Peter.
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Loading...