下面的宏显示了如何切换快捷菜单的可用性状态。

Sub ToggleCommandBars()

Dim cbEnabled As Boolean

cbEnabled = Not CommandBars(25).Enabled

CommandBars(25).Enabled = cbEnabled ' shortcutmenu for cells

CommandBars(26).Enabled = cbEnabled ' shortcutmenu for columns

CommandBars(27).Enabled = cbEnabled ' shortcutmenu for rows

CommandBars("Toolbar List").Enabled = cbEnabled ' shortcutmenu for toolbars

End Sub