6

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 年に変更されましたか?

4

2 に答える 2

3

このタイプのコードが (独自のアドインまたは会社が使用する他のアドインに) 存在するかどうかを確認し、コメント アウトするか、アドインの _Shutdown イベントに移動するかどうかを確認します。

//reset commandbars
Application.CommandBars["Cell"].Reset();
于 2012-05-10T07:37:20.033 に答える