|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
打开vba面板,在“ThisWorkbook”上双击两下,加入以下代码:- Private Sub Workbook_Open()
- '**********************************
- Application.Visible = True
- On Error Resume Next
- With Application
- .ActiveWindow.Caption = ""
- .Caption = "工作表名称"
- .DisplayFormulaBar = True
- End With
-
- Dim BarCtlBtn As CommandBarButton
- Dim BarCtlBtnP As CommandBarPopup
- Application.CommandBars("MyMenu").Delete
- With Application.CommandBars.Add("MyMenu", msoBarTop, False, False)
-
- '******************************
- '******************************
- Set BarCtlBtnP = .Controls.Add(Type:=msoControlPopup, id:=1)
- With BarCtlBtnP
- .Caption = "【菜单1】 "
- '.BeginGroup = False
- End With
-
- Set BarCtlBtn = BarCtlBtnP.Controls.Add(Type:=msoControlButton)
- With BarCtlBtn
- .Style = msoButtonIconAndCaption
- .Caption = "【菜单1—1】 "
- .FaceId = 247
- .OnAction = "sub过程名称"
- End With
-
- Set BarCtlBtn = BarCtlBtnP.Controls.Add(Type:=msoControlButton)
- With BarCtlBtn
- .Style = msoButtonIconAndCaption
- .Caption = "【菜单1—2】 "
- .FaceId = 247
- .OnAction = "sub过程名称"
- End With
-
-
- '****************************菜单选项:*************************
- Set BarCtlBtnP = .Controls.Add(Type:=msoControlPopup, id:=1)
- With BarCtlBtnP
- .Caption = "【菜单2】 "
- '.BeginGroup = False
- End With
-
-
- Set BarCtlBtn = BarCtlBtnP.Controls.Add(Type:=msoControlButton)
- With BarCtlBtn
- .Style = msoButtonIconAndCaption
- .Caption = "【菜单2—1】"
- .FaceId = 3650
- .OnAction = "sub过程名称"
-
- End With
- Set BarCtlBtn = BarCtlBtnP.Controls.Add(Type:=msoControlButton)
- With BarCtlBtn
- .Style = msoButtonIconAndCaption
- .Caption = "【菜单2—2】"
- .FaceId = 3648
- .OnAction = "sub过程名称"
- End With
- .Visible = True
- End With
- '****************************菜单选项:*************************
-
-
- End Sub
- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- On Error Resume Next
- Application.CommandBars("MyMenu").Delete
- Application.CommandBars("MyMenu2").Delete
- Application.DisplayFormulaBar = True
- '-------
- End Sub
复制代码 把代码sub名加入到相应的菜单中,所有的sheet都可以使用了
|
|