VSTO add menu item in Excel 2003 with C #
I am developing an Excel 2003 add-in and am trying to make my own menu like this:
Application.ScreenUpdating = true;
Application.MenuBars.Add("MyMenu");
Application.MenuBars["MyMenu"].Menus.Add("MyMenuItem1", null, null);
Everything seems to work fine, but I can't see my menu at all.
any ideas why?
0
Bob
a source
to share
1 answer
You will need to link to the menu item in your own code. Otherwise, the menu item will be destroyed as soon as the "add menu" method is displayed.
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);
}
}
See this article on MSDN for details .
+3
a source to share