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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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,215,417
Messages
6,124,791
Members
449,188
Latest member
Hoffk036

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