3 つの異なるコード サンプルを試しましたが、すべて失敗します。
これは MSFT 従業員のコード (範囲でコンテキスト メニューを表示する方法) です。他の 2 つのサンプルのコードはほとんど同じです。
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 で) 実行しても、[更新] メニュー項目はありません。
何が不足している可能性がありますか、またはこの機能は 2007 年から 2010 年に変更されましたか?