Discussion:
CommandBar item creation?
(too old to reply)
Brian
2007-08-14 20:12:19 UTC
Permalink
Hello,

In which event is it most appropriate to create a CommandBar button that
displays information about the currently open document?

A little background on my Add In: VB6 COM add-in written to display and
change a Custom Document Property for any Word document.

Right now, I create my button on the IDTExtensibility2_OnConnection event,
which essentially fires when Word is launched. I then update the caption of
the button to display the custom document property on the following events
raised for the Word Application object:

DocumentChange
DocumentOpen
NewDocument

I am noticing, however, that as users move through documents, in some cases,
the reference to my button seems to go away, and when I try to set the
button's caption property I get an "Object variable or with block not set"
exception.

What is the best practice for creating items in the CommandBar in Word for
an addin whose items could change depending on the document that is opened?
Should I recreated the button on DocumentChange??? That seems like a lot of
overhead (and potentially "screen flickering") just to maintain a reference
to the button...

TIA!!!

Brian
Shauna Kelly
2007-08-18 00:41:14 UTC
Permalink
Hi Brian

What version of Word are you using? Can you show us the code that you're
using to create and update the button? And, what template is used to create
the documents for which this button is appropriate?

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by Brian
Hello,
In which event is it most appropriate to create a CommandBar button that
displays information about the currently open document?
A little background on my Add In: VB6 COM add-in written to display and
change a Custom Document Property for any Word document.
Right now, I create my button on the IDTExtensibility2_OnConnection event,
which essentially fires when Word is launched. I then update the caption of
the button to display the custom document property on the following events
DocumentChange
DocumentOpen
NewDocument
I am noticing, however, that as users move through documents, in some cases,
the reference to my button seems to go away, and when I try to set the
button's caption property I get an "Object variable or with block not set"
exception.
What is the best practice for creating items in the CommandBar in Word for
an addin whose items could change depending on the document that is opened?
Should I recreated the button on DocumentChange??? That seems like a lot of
overhead (and potentially "screen flickering") just to maintain a reference
to the button...
TIA!!!
Brian
Brian
2007-08-20 17:16:20 UTC
Permalink
I am using Word XP (aka Word 2002).

I am in the process of updating the code. I am using the standard code to
create buttons on the application level CommandBars object.

The button is shown/displayed regardless of what template is used to create
the document.

Apparently the WindowActivate method is the appropriate method to create any
UI that is Document centric, as is the case for me. But would still
appreciate any feedback anyone might have for creating UI elements (i.e.
buttons on CommandBar) that are document centric (i.e. can be different for
each document that is opened)...

-Brian
Post by Shauna Kelly
Hi Brian
What version of Word are you using? Can you show us the code that you're
using to create and update the button? And, what template is used to
create the documents for which this button is appropriate?
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Post by Brian
Hello,
In which event is it most appropriate to create a CommandBar button that
displays information about the currently open document?
A little background on my Add In: VB6 COM add-in written to display and
change a Custom Document Property for any Word document.
Right now, I create my button on the IDTExtensibility2_OnConnection event,
which essentially fires when Word is launched. I then update the caption of
the button to display the custom document property on the following events
DocumentChange
DocumentOpen
NewDocument
I am noticing, however, that as users move through documents, in some cases,
the reference to my button seems to go away, and when I try to set the
button's caption property I get an "Object variable or with block not set"
exception.
What is the best practice for creating items in the CommandBar in Word for
an addin whose items could change depending on the document that is opened?
Should I recreated the button on DocumentChange??? That seems like a lot of
overhead (and potentially "screen flickering") just to maintain a reference
to the button...
TIA!!!
Brian
Loading...