在Excel共享加载项的现有菜单中创build一个子菜单
我正在开发一个Excel共享加载项,其中包含使用Excelmacros创build的“ Custom
”菜单。 现在我想使用Csharp Shared Add -in在Custom
菜单下创build一个子菜单。 Iam使用下面的代码来做到这一点,但没有帮助
oStandardBar = oCommandBars["Custom"]; oCmdBarCtrl = oStandardBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true); oCmdBarCtrl.Visible = false; oCmdBarCtrl.Caption = "Sub Menu1";
但是它并没有创build一个子菜单,就好像我给“帮助”来代替自定义,我得到了创build的菜单。 任何解决这个问题?
以下是一个快速样本,可以帮助您:
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;