我正在开发一个Excel共享加载项,其中包含使用Excel宏创建的名为Custom
的菜单。现在我想使用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";
但它没有创建一个子菜单,就好像我用“帮助”代替自定义我得到菜单创建。为此做的任何工作?
答案 0 :(得分: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;