tags:

views:

1004

answers:

1

Hi there,

I'm developing an Excel 2003 add-on and trying to make my own menu like so:

Application.ScreenUpdating = true;
Application.MenuBars.Add("MyMenu");
Application.MenuBars["MyMenu"].Menus.Add("MyMenuItem1", null, null);

It seems to run just fine but I can't see my menu at all.

any ideas why?

+3  A: 

You will have to hold a reference to the menu item in your own code. Otherwise the menu item will be destroyed as soon as your "menu adding" method exits.

So try this instead:

class MyAddin {

     private Office.CommandBarButton myMenuItem;

     private void AddMenuItem() 
     {
         Application.ScreenUpdating = true;
         Application.MenuBars.Add("MyMenu");
         myMenuItem = Application.MenuBars["MyMenu"].Menus.Add("MyMenuItem1", null, null);
     }
}

For more details, see this article on MSDN.

Frederick
Great, thanks a million!