I tried 3 different code examples and they all fail.
Here is the code from an MSFT employee ( How to show the context menu in a range ), the other two examples pretty much have the same code:
private void ThisAddIn_Startup(object sender, System.EventArgs e) { CommandBar cellbar = this.Application.CommandBars["Cell"]; CommandBarButton button = (CommandBarButton) cellbar.FindControl(MsoControlType.msoControlButton, 0, "MYRIGHTCLICKMENU", Missing.Value, Missing.Value); if (button == null) { // add the button button = (CommandBarButton) cellbar.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, cellbar.Controls.Count, true); button.Caption = "Refresh"; button.BeginGroup = true; button.Tag = "MYRIGHTCLICKMENU"; button.Click += new _CommandBarButtonEvents_ClickEventHandler(MyButton_Click); } } private void MyButton_Click(CommandBarButton cmdBarbutton, ref bool cancel) { System.Windows.Forms.MessageBox.Show("MyButton was Clicked", "MyCOMAddin"); }
I expect to see the Refresh menu item when I right-click on a cell. However, when executing the above code (in Excel 2010), the menu item "Refresh" is missing.
What am I missing or has this functionality changed from 2007 to 2010?
source share