Word loses reference to COM object menu items (CommandBarControl) (313948)



The information in this article applies to:

  • Microsoft Office Word 2003
  • Microsoft Word 2002

This article was previously published under Q313948

SYMPTOMS

When you add a menu item to Microsoft Word from a Visual Basic COM add-in by using the steps in the following article or by using a similar method, the menu item does not work as expected:

238228 How to build an Office 2000 COM add-in in Visual Basic

CAUSE

This problem occurs because Word requires the menu item to be unique. If the menu item is not unique, Word loses its reference to the CommandBarControl object.

Only Word has this requirement. Microsoft Excel and Microsoft PowerPoint do not. Therefore, if you use the same code to add controls in PowerPoint and Excel, the code works as expected.

RESOLUTION

The following resolution comes verbatim from the top of page 319 in the Microsoft Office XP Developers Guide (Microsoft Press, ISBN 0-7356-1242-0):

If your add-in will run in Word, you must also set the Tag property for the CommandBarButton object to a unique String value. This makes sure the command bar button will respond to the Click event and load the add-in for each new document window that the user opens. Because the Tag property provides you with additional information about the control, it is a good idea to set the Tag property for a command bar button that loads a COM add-in in any host application.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbpending KB313948