How to add a menu item to the context menu of an Excel 2010 cell - old code does not work

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?

+6
source share
1 answer

Check if this type of code exists (either in your own add-on or in any other application used by your company), and if it either comments on it or moves it to the _Shutdown event for adding.

 //reset commandbars Application.CommandBars["Cell"].Reset(); 
+3
source

Source: https://habr.com/ru/post/915365/


All Articles