如何将菜单项添加到Excel 2010单元格上下文菜单 – 旧代码不起作用

我已经尝试了3个不同的代码示例,它们都失败了。

以下是MSFT员工的代码( 如何显示范围内的上下文菜单 ),另外两个样本的代码几乎完全相同:

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"); } 

我期待在右键单击单元格时看到名为刷新的菜单项。 然而运行上面的代码(在Excel 2010中)没有“刷新”菜单项。

真的很感激任何提示,我可能会缺less什么,或者如果这个function从2007年改变到2010年?

检查这种types的代码是否存在(或者在你自己的插件或者你的公司使用的任何其他插件中),如果它注释掉或者把它移到插件的_Shutdown事件。

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