How do you refer to command button using its OnAction

mikeburg

Board Regular
Joined
Jun 23, 2005
Messages
165
Change faceid of a command bar button from other VBA code?
I have the following code to add a button to my tool bar:

Dim CB As CommandBar
Dim CBB2 As CommandBarButton
Set CB = Application.CommandBars(1)
Set CBB2 = CB.Controls.Add(Type:=msoControlButton, _
before:=CB.Controls.Count, ID:=59, temporary:=True)
With CBB2
.FaceId = 40
.Caption = "Changes to down on enter"
.OnAction = "CBB2CursorMovementRightOrLeft"
End With

For changing the FaceID, I can refer to it by its Caption, eg:
Application.CommandBars(1).Controls("Changes to down on enter").FaceId = 50

How can i refer to it by its OnAction?

Thanks for any & all help. mikeburg
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about something like this:

Dim c As CommandBars.CommandBarControl
Dim cControl As CommandBars.CommandBarControl

For Each c In CommandBars(1).CommandBarControls
If c.OnAction = "Changes to down on enter" Then
Set cControl = c
Exit For
End If
Next c
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

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