Change the availability for a menu item using VBA in Microsoft Excel

The macro below shows how you can toggle the availability state for a menu item.

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


Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.