在 Excel 共享加载项的现有菜单中创建子菜单

发布于 2024-08-29 16:17:12 字数 463 浏览 4 评论 0原文

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

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

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

I am developing a Excel shared Add-in which has the menu called Custom which is created using Excel Macros. Now i want to create a submenu under the Custom menu using Csharp Shared Add -in. Iam using the below code for doing this but no help

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

But it does not create a submenu, where as if i give "Help" in place of Custom i get the menu created. any work around for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2024-09-05 16:17:12

这是一个可以帮助您的快速示例:

        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;

Here's a quick sample to help you on your way:

        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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文