Command Button Collection?

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
Is it possible to iterate through a collection of command buttons in my workbook, changing the caption on them?

e.g.

Code:
for each button in commandbuttons
commandbutton.text = "mychangedtext"
next button

cheers guys
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If you are using worksheet embeeded Buttons created from the Controls Toolbar use this :

Code:
Sub ChangeCaptionOf_ButtonsFrom_ControlsToolBar_TEST(Sht As Worksheet)

    Dim oCbt  As OLEObject
    
    For Each oCbt In Sheet1.OLEObjects
    
    If oCbt.progID = "Forms.CommandButton.1" Then
            oCbt.Object.Caption = "MyChangedText"
        End If
    Next

End Sub

Sub Example1()

    ChangeCaptionOf_ButtonsFrom_ControlsToolBar_TEST Sheet1

End Sub



For Buttons created from the Forms ToolBar use this :

Code:
Sub ChangeCaptionOf_ButtonsFrom_FormsToolBar_TEST(Sht As Worksheet)

    Dim oButton  As Shape
    
    For Each oButton In Sheet1.Shapes
    
    If TypeName(oButton.OLEFormat.Object) = "Button" Then
        oButton.OLEFormat.Object.Caption = "MyChangedText"
    End If
    
    Next

End Sub

Sub Example2()

    ChangeCaptionOf_ButtonsFrom_FormsToolBar_TEST Sheet1

End Sub


Regards.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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