haibin_sh

Hi,

I used Word 2003 add-in to add a new menu to the menu bar.

Office.CommandBar menubar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar;

cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add(
Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true);

menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(
Office.MsoControlType.msoControlButton, missing, missing, missing, true);

Later I found I could not remove the new menu. I uninstalled the package and used Tools/Customize to remove the new menu. But It failed.

Even after I programmatically deleted the menu, when I opened a new Word document, it's still there.

Any idea how I can remove it Does it has something to do with Word Template

Regards,

Haibin



Re: Visual Studio Tools for Office how to remove the newly-added menu

Cindy Meister

Hi Haibin

In your sample code I'm missing the CustomizationContext.

Since Word can save changes to CommandBars in

- a document

- the template attached to a document

- a globally available template (Add-in)

- the NormalTemplate (the default template)

it's imperative that your code tells Word explicitly where the change should be made. If you do not do that, then Word guesses. And if you later tell Word to do something else with the commandbar (or control), Word may choose to save that change in a different "context" (file) than where the button was created. This can create a huge mess, as you're experiencing.

Look up Application.CustomizationContext in the Word object model help. The VSTO examples on msdn generally don't mention it because those were written originally for Word document-level customizations. And in those projects CustomizationContext is automatically the ActiveDocument. But this isn't the case with an Add-in.