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

Sub ToggleMenuControls()

Dim m As CommandBarControl, mi As CommandBarControl

Set m = CommandBars.FindControl(ID:=30002) ' File Menu

If m Is Nothing Then Exit Sub

For Each mi In m.Controls

If mi.ID = 18 Then mi.Enabled = Not mi.Enabled

' toggles the state for the Print menu

Next mi

Set mi = Nothing

Set m = Nothing

End Sub