添加一菜单:
工具 ->
自定义... ->
命令(tab) ->
重排命令(Btn) ->
工具栏 (Radio Btn) ->
工作表菜单栏 (dropdown list) ->
增加(Btn) ->
新菜单 (Select) ->
确定(Btn) ->
更改所选内容 (Btn) -> 这里可以改名、删除、指定宏等
给菜单增加子菜单:
菜单栏选之前建的 -> 增加 -> 宏 -> 自定义菜单项 -> 确定
VBA代码方式增加菜单:
Dim cbMainMenuBar As CommandBar
Dim cbcCutomMenu As CommandBarControl
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls(
"新菜单(&N)").Delete
On Error GoTo 0
Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
Set cbcCutomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup)
cbcCutomMenu.Caption = cutomMainMenuText
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "子菜单1(&P)"
.OnAction = "子菜单1事件"
End With
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "子菜单1(&H)"
.OnAction = "子菜单2事件"
.BeginGroup = True
End With
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "子菜单3(&S)"
.OnAction = "子菜单3事件"
End With
删除菜单VBA代码:
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("新菜单(&N)").Delete
On Error GoTo 0