Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Missing Custom CommandBar

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tont - 28 Sep 2007 17:59 GMT
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 - 29 Sep 2007 13:02 GMT
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

> Hi All
>
[quoted text clipped - 24 lines]
>
> Thanks for taking the time to read this + Cheers - Peter.
Russ - 30 Sep 2007 00:31 GMT
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?

> Hi All
>
[quoted text clipped - 37 lines]
>>
>> Thanks for taking the time to read this + Cheers - Peter.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Tont - 30 Sep 2007 03:40 GMT
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

> Tont,
> The screen probably needs to be forced to redraw its graphics.
[quoted text clipped - 45 lines]
> >>
> >> Thanks for taking the time to read this + Cheers - Peter.
Shauna Kelly - 30 Sep 2007 04:10 GMT
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.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.