How to hide menu commands in VBA code

mcomp72

Board Regular
Joined
Aug 14, 2016
Messages
160
I have created a menu for my Excel macro workbook, but there is an instance where I would want most of the items listed in the menu to be either disabled/greyed out/invisible. I have been trying to write the code to do this, but can't quite figure out the syntax. I've searched around online, but haven't come across anything yet that gave me the solution.

Here's part of my code that runs on Workbook_Open:

Code:
Set objBtn = objPopUp.Controls.Add
With objBtn
   .Caption = "Globals"
   .Tag = "Globals"
   .OnAction = "Globals_Button"
   .Style = msoButtonCaption
End With

(This isn't the entire code that creates the menu, but that is quite long, so I didn't put it all here. The menu definitely is created and works fine, though. Let me know if you would like to see the entire code for creating the menu, and I will post it.)

Later in my code when I want to make this disabled, here is the line of code I currently have:

Code:
Application.CommandBars.FindControl(Tag:="Globals").Enabled = False

This line throws an error: Run-time error 91 - Object variable or With Block Variable Not Set

Anyone know what I'm missing here?
 
Last edited:

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

mcomp72

Board Regular
Joined
Aug 14, 2016
Messages
160
I closed my workbook to step away from it for a while. When I came back and opened it, I wasn't getting the above error anymore. It seems to work fine now. I don't understand, but I'm going to cross my fingers and hope whatever was causing the problem is gone for good.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,306
Messages
5,527,921
Members
409,793
Latest member
mavrik_stet

This Week's Hot Topics

Top