Creating a CommadBar button?

B

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
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
 
N

Nick Hebb

You shouldn't have to re-create the button. I don't do Word add-ins,
but I have had some issues with my add-in losing reference to the
current worksheet. If have sprinkled some lines around the code that
have resolved the problem. They look something like the following:

If wks = Nothing Then
Set wks = gxlApp.ActiveSheet ' where gxlApp is a global reference
to the application
' Log the problem in the error log
End If

Obviously Word is different, but that technique may work for you.

Nicholas Hebb
BreezeTree Software
http://www.breezetree.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top