使用下面的宏,您可以切换工作簿菜单栏,标准工具栏和自定义命令栏的可用性。

第一次运行宏时,菜单和标准栏被禁用,自定义工具栏被启用。

下次运行宏时,将启用菜单和“标准”栏,而自定义CommandBar将被禁用。

Sub ToggleCommandBars()

Dim cbEnabled As Boolean

' get the current commandbar state

cbEnabled = Not Application.CommandBars(1).Enabled

' apply the new state to the Workbook Menu Bar

Application.CommandBars(1).Enabled = cbEnabled

' apply the new state to the Standard toolbar

Application.CommandBars("StandardOPE").Enabled = cbEnabled

' apply the new state to a custom commandbar (the oposite of the previous two)

Application.CommandBars("MyCustomCommandBar").Enabled = Not cbEnabled

End Sub