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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Assuming that you actually have menus for "Proposal" on your main XL menu...this should work fine. However, there is no "real" need to inclose this within a With...End With block.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DisableMenuItems()
    Application.CommandBars(1).Controls("Proposal").Controls("Enter/Edit Invoice Data...").enabled = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> EnableMenutItems()
    Application.CommandBars(1).Controls("Proposal").Controls("Enter/Edit Invoice Data...").enabled = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Where is your menu item "Proposal" located?

Also, do you have code that is creating these menus?
 
Upvote 0
"Proposal" is located between "Window" and "Help". Here is my code for creating the menu items.

Sub createmenu()
' CREATING THE MENU
Dim Helpmenu As CommandBarControl
Dim Newmenu As CommandBarPopup
Dim MenuItem As CommandBarControl
Dim Submenuitem As CommandBarButton
Call DeleteMenu
Set Helpmenu = commandbars(1).FindControl(ID:=30010)
If Helpmenu Is Nothing Then
Set Newmenu = commandbars(1).Controls _
.Add(Type:=msoControlPopup, temporary:=True)
Else
Set Newmenu = commandbars(1).Controls _
.Add(Type:=msoControlPopup, Before:=Helpmenu.Index, _
temporary:=True)
End If
Newmenu.Caption = ("&Proposal")
' CREATE "ENTER PROPOSAL CRITERIA" MENU ITEM
Set MenuItem = Newmenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "&Enter/Edit Proposal Criteria..."
.FaceId = 162
.OnAction = "Proposalcriteria"
End With
' CREATE "ENTER INVOICE DATA" MENU ITEM
Set MenuItem = Newmenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "&Enter/Edit Invoice Data..."
.FaceId = 162
.OnAction = "Invoicedata"

NL
 
Upvote 0
Okay, then try this code...
Code:
Sub Test()
Application.CommandBars(1).Enabled = False
End Sub
What happens when you run this?
 
Upvote 0
Okay, now reset it by running that code with TRUE.

Now, try this code...
Code:
Sub Test2()
Application.CommandBars(1).Controls("Proposal").Enabled=False
End Sub
What happens now?
 
Upvote 0

Forum statistics

Threads
1,225,563
Messages
6,185,703
Members
453,315
Latest member
funktgf

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