none
commandBarButton not visible RRS feed

  • Question

  • hi all

    i need your advice i have a scenario where i have 2 excel addin both addin add commanbar button now the problem is that

    i can only see 1 command bar button there must be 2 as 2 addin are installed

    1st addin code

    Application.CommandBars["Cell"].Reset();

    this.oBtn2 = (CommandBarButton)this.Application.CommandBars["Cell"].Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 2, 5);
                CommandBarButton commandBarButton = this.oBtn2;
         
                commandBarButton.Caption = "Send email to gmail";
                commandBarButton.FaceId = 326;
                commandBarButton.BeginGroup = true;
               // commandBarButton.Tag = "MYRIGHTCLICKMENU2";

                commandBarButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
                oBtn2.Click += new _CommandBarButtonEvents_ClickEventHandler(oBtn_Click);

    2.secoond addin code

    Application.CommandBars["Cell"].Reset();

    this.oBtn2 = (CommandBarButton)this.Application.CommandBars["Cell"].Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 2, 5);
                CommandBarButton commandBarButton = this.oBtn2;
         
                commandBarButton.Caption = "Send email to hotmail";
                commandBarButton.FaceId = 326;
                commandBarButton.BeginGroup = true;
               // commandBarButton.Tag = "MYRIGHTCLICKMENU2";

                commandBarButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
                oBtn2.Click += new _CommandBarButtonEvents_ClickEventHandler(oBtn_Click);

    i can only see one obutton

    can you please help whats wrong in this

    Wednesday, July 11, 2012 6:52 PM

Answers

  • Please specify the version of Excel invovled in the question.

    In both sets of code you have the line:

       Application.CommandBars["Cell"].Reset();

    The Reset command specifically removes all customizations to the CommandBar. So when each add-in loads it automatically removes the customization added by the other add-in. If you comment out these two lines I think you'll see both buttons.

    Note that this line may have been added to the code because buttons were being added every time the add-in starts, resulting in multiple buttons. If that's the problem, then you need to write code to specifically look for the button an add-in creates. If it's there, you can either delete it and re-create it, or simply link the existing button to the code's event handler.


    Cindy Meister, VSTO/Word MVP

    Thursday, July 12, 2012 2:40 PM
    Moderator