1

我正在开发一个 Excel 共享加载项,其中包含Custom使用 Excel 宏创建的菜单。现在我想Custom使用 Csharp Shared Add -in 在菜单下创建一个子菜单。我正在使用以下代码执行此操作,但没有帮助

oStandardBar = oCommandBars["Custom"];
oCmdBarCtrl = oStandardBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true);
oCmdBarCtrl.Visible = false;
oCmdBarCtrl.Caption = "Sub Menu1";

但它不会创建子菜单,就好像我用“帮助”代替“自定义”一样,我会创建菜单。有什么解决方法吗?

4

1 回答 1

1

这是一个快速示例,可帮助您顺利进行:

        var m_toolbar = this.Application.CommandBars.Add("WpfAddIn",
            Office.MsoBarPosition.msoBarTop, false, true);

        var mainMenu = (Office.CommandBarPopup)m_toolbar.Controls
            .Add(Office.MsoControlType.msoControlPopup, 
            missing, missing, missing, true);
        mainMenu.Caption = "Main menu";

        var subMenu1 = (Office.CommandBarButton)mainMenu.Controls
            .Add(Office.MsoControlType.msoControlButton, 
            missing, missing, missing, true);
        subMenu1.Caption = "Sub menu 1";
        subMenu1.FaceId = 1958;

        var subMenu2 = (Office.CommandBarPopup)mainMenu.Controls
            .Add(Office.MsoControlType.msoControlPopup,
            missing, missing, missing, true);
        subMenu2.BeginGroup = true;
        subMenu2.Caption = "Sub menu 2";

        var subMenu2Button = (Office.CommandBarButton)subMenu2.Controls
            .Add(Office.MsoControlType.msoControlButton,
            missing, missing, missing, true);
        subMenu2Button.Caption = "Sub menu 1";
        subMenu2Button.FaceId = 1958;

        m_toolbar.Visible = true;
于 2010-05-19T20:47:30.680 回答