Excel vba中控制菜单按钮 commandbars知多少? 图文

2018年9月30日23:44:06Excel vba中控制菜单按钮 commandbars知多少? 图文已关闭评论 11,744 views
微信公众号 【EXCEL880】 QQ群【165159540】 Excel课程咨询 请加郑广学老师微信EXCEL880B

Sub test()

'视图工具栏中,各种工具对应的英文名称

'worksheet menu bar表示工作表菜单栏 , 编号是 1 

Application.CommandBars("worksheet menu bar").Enabled = False

'formatting表示格式工具栏, 编号 4 

Application.CommandBars("Formatting").Visible = False

'standard表示常用工具栏, 编号 3 

Application.CommandBars("Standard").Visible = falsae

'Toolbar list表示右键工具栏

Application.CommandBars("Toolbar list").Enabled = False 

 'Ply表示屏蔽工作表标签栏右键菜单

Application.CommandBars("Ply").Enabled = False 

'Cell表示鼠标右键点工作表区域出来的快捷菜单,编号是 36

Application.CommandBars(" Cell ").Enabled = False

'drawing表示绘图工具栏

Application.CommandBars("Drawing").Visible = False

'control toolbox表示控件工具箱

Application.CommandBars("Control Toolbox").Visible = False

'reviewing表示审阅工具

Application.CommandBars("Reviewing").Visible = False

Application.CommandBars("金山快译").Visible = False

'dispalyformulabar表示编辑栏

Application.DisplayFormulaBar = False

Application.CommandBars("Visual Basic").Visible = False

Application.CommandBars("Web").Visible = False

Application.CommandBars("Protection").Visible = False

Application.CommandBars("Borders").Visible = False

Application.CommandBars("Forms").Visible = False

Application.CommandBars("Formula Auditing").Visible = False

Application.CommandBars("Watch Window").Visible = False

'pivottable表示数据透视表

Application.CommandBars("PivotTable").Visible = False

'chart表示图表

Application.CommandBars("Chart").Visible = False

'picture表示图片

Application.CommandBars("Picture").Visible = False

Application.CommandBars("Exit Design Mode").Visible = False

'external data表示外部数据

Application.CommandBars("External Data").Visible = False

End Sub

别忘了在thisworkbook模块中加上下面的事件,用于还原菜单栏等

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.CommandBars("worksheet menu bar").Enabled = True

Application.CommandBars("Formatting").Visible = True

Application.CommandBars("Standard").Visible = True

Application.CommandBars("Drawing").Visible = True

Application.CommandBars("Control Toolbox").Visible = True

Application.CommandBars("Reviewing").Visible = True

Application.CommandBars("金山快译").Visible = True

Application.DisplayFormulaBar = True

End Sub