Multiple FindControls ID's

lsab

New Member
Joined
Aug 16, 2012
Messages
16
I'm trying to create a macro to remove multiple items from the right click menu within a sheet.

Thus far I have:

Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=855)
Ctrl.Enabled = False

How can I in-cooperate multiple menu items to be disabled? i.e. 855, 478, 1576
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can use a array

Sub MenuControl_False1()
' Excel 2000 - 2003
Dim ctrl As Office.CommandBarControl
Dim IDnum As Variant
Dim N As Integer

IDnum = Array("19", "21")
For N = LBound(IDnum) To UBound(IDnum)

For Each ctrl In Application.CommandBars.FindControls(ID:=IDnum(N))
ctrl.Enabled = False
Next ctrl

Next N
End Sub

Sub MenuControl_True1()
' Excel 2000 - 2003
Dim ctrl As Office.CommandBarControl
Dim IDnum As Variant
Dim N As Integer

IDnum = Array("19", "21")
For N = LBound(IDnum) To UBound(IDnum)

For Each ctrl In Application.CommandBars.FindControls(ID:=IDnum(N))
ctrl.Enabled = True
Next ctrl

Next N
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,688
Messages
6,126,213
Members
449,301
Latest member
rcocrane99

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