How to hide menu commands in VBA code

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top