在VBA Excel的子菜单下添加子菜单可以通过以下步骤实现:
Private Sub UserForm_Initialize()
Dim submenu As CommandBarPopup
Dim subsubmenu As CommandBarPopup
' 创建主菜单
Set submenu = Application.CommandBars("Worksheet Menu Bar").Controls.Add(Type:=msoControlPopup, Before:=6)
submenu.Caption = "子菜单"
' 创建子菜单
Set subsubmenu = submenu.Controls.Add(Type:=msoControlPopup)
subsubmenu.Caption = "子菜单1"
' 添加子菜单项
subsubmenu.Controls.Add Type:=msoControlButton, Before:=1
subsubmenu.Controls(1).Caption = "子菜单项1"
' 创建另一个子菜单
Set subsubmenu = submenu.Controls.Add(Type:=msoControlPopup)
subsubmenu.Caption = "子菜单2"
' 添加子菜单项
subsubmenu.Controls.Add Type:=msoControlButton, Before:=1
subsubmenu.Controls(1).Caption = "子菜单项2"
End Sub
这样就成功在VBA Excel的子菜单下添加了子菜单。请注意,以上代码是一个示例,你可以根据自己的需求进行修改和扩展。
领取专属 10元无门槛券
手把手带您无忧上云