Excel 要堆叠的自定义外接程序工具栏
我有以下生成自定义工具栏的代码。我的问题是,当我添加更多按钮/弹出窗口时,它们会在水平方向上相互广告。这意味着在加入4/5后,它会占据大量的空间。有没有一种方法可以像在菜单命令栏中那样,将它们堆叠在一个垂直的3个列表中Excel 要堆叠的自定义外接程序工具栏,excel,vba,Excel,Vba,我有以下生成自定义工具栏的代码。我的问题是,当我添加更多按钮/弹出窗口时,它们会在水平方向上相互广告。这意味着在加入4/5后,它会占据大量的空间。有没有一种方法可以像在菜单命令栏中那样,将它们堆叠在一个垂直的3个列表中 Sub CreateMyMenu() Dim myCB As CommandBar Dim myCBtn1 As CommandBarButton Dim myCBtn2 As CommandBarButton Dim myCPup1 As Com
Sub CreateMyMenu()
Dim myCB As CommandBar
Dim myCBtn1 As CommandBarButton
Dim myCBtn2 As CommandBarButton
Dim myCPup1 As CommandBarPopup
Dim myCPup2 As CommandBarPopup
Dim myCP1Btn1 As CommandBarButton
Dim myCP1Btn2 As CommandBarButton
' Delete the CommandBar if it exists already
On Error Resume Next
Application.CommandBars("MyMenu").Delete
' Create a new CommandBar
Set myCB = CommandBars.Add(Name:="MyMenu", Position:=msoBarFloating)
' Add button 1 to this bar
Set myCBtn1 = myCB.Controls.Add(Type:=msoControlButton)
With myCBtn1
.Caption = "1st Button"
.Style = msoButtonCaption '<- force caption text to show on your button
End With
' Add popup menu 1 to this bar - this is a menu that folds out
Set myCPup1 = myCB.Controls.Add(Type:=msoControlPopup)
myCPup1.Caption = "Statistics"
' Add button 1 to popup menu 1
Set myCP1Btn1 = myCPup1.Controls.Add(Type:=msoControlButton)
With myCP1Btn1
.Style = msoButtonAutomatic
.FaceId = 487
End With
' Add button 2 to popup menu 1
Set myCP1Btn1 = myCPup1.Controls.Add(Type:=msoControlButton)
With myCP1Btn1
.Caption = "Click me!"
.Style = msoButtonIconAndCaption
.FaceId = 59
.OnAction = "SubItworks" '<- call the sub routine SubItWorks
End With
' Add a second button to this bar
Set myCBtn2 = myCB.Controls.Add(Type:=msoControlButton)
With myCBtn2
.FaceId = 17 ' <- Face Id 17 is a barchart icon
.Caption = "Barchart" '<- shows when hovering mouse over icon
End With
' Add popup menu 1 to this bar - this is a menu that folds out
Set myCPup1 = myCB.Controls.Add(Type:=msoControlPopup)
myCPup1.Caption = "Settings"
' Show the command bar
myCB.Visible = True
End Sub
通过更改以下选项,它可以工作:
CommandBars.Add
到
CommandBars.Add
CommandBars.Button.Add