disable menu item - why doesn't this code work?

Nick147

Board Regular
Joined
Apr 24, 2003
Messages
111
This code doesn't work for some reason. I get a a runtime error "Invalid procedure or argument"

Sub disablemenutitems()
With Application.commandbars("Proposal").Controls
.Item("Enter/Edit Invoice Data...").Enabled = False
End With
End Sub

Sub enablemenuitems()
With Application.commandbars("Proposal").Controls
.Item("Enter/Edit Invoice Data...").Enabled = True
End With
End Sub

These two subs work fine if I use "File" in place of "Proposal" and "Print..." in place of "Enter/Edit Invoice Data...".

NL
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Okay, then re-enable it by running that code with TRUE. Now try this code...
Code:
Sub Test3()
Application.CommandBars(1).Controls("Proposal").Controls("Edit/Enter Invoice Data...").Enabled = False
End Sub
What happens now?
 
Upvote 0
Okay, then the control "Edit/Enter Invoice Data..." does not exist inside your "Proposal" menu. I have tested this on XL 97 & XL 2003 and it works fine for me.
 
Upvote 0
What do you mean it doesn't "exist"? When I select "Proposal" I can see "Enter/Edit Invoice Data..." and when I select "Enter/Edit Invoice Data..." the .Onaction (see code) shows the "invoicedata" userform just like it suppose to.
 
Upvote 0
Don't know why this is necessary, but this should do the trick. I'll need to look into this further at a later time.
Code:
Sub Test3() 
Application.CommandBars(1).Controls("Proposal").Controls(2).Enabled = False
End Sub
 
Upvote 0
YES! that worked. I think it may have had something to do with me using the same "Menuitem" variable to create all of my new menu items. I was just starting to follow up on this just before I got you last reply.

Thanks so much for you help.
NL
 
Upvote 0

Forum statistics

Threads
1,226,243
Messages
6,189,840
Members
453,575
Latest member
Taljanin

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