buttons on worksheet.. how to loop through them?

muffins

Board Regular
Joined
Jun 18, 2002
Messages
86
hi everyone,

i have several buttons and checkboxes on a worksheet. i need to loop through them to change their property. May I know how?

thanks!!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Like this:

Code:
Sub Test()
    Dim Ctrl As OLEObject
    For Each Ctrl In ActiveSheet.OLEObjects
        MsgBox Ctrl.Name
    Next Ctrl
End Sub
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
Did you check the properties of the object in question? if 'caption' isn't one of them, check for a synonym.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
You have to use the Object property, then the Caption property, like this:

Code:
Sub Test()
    Dim Ctrl As OLEObject
    Dim x As String
    For Each Ctrl In ActiveSheet.OLEObjects
        On Error Resume Next
        MsgBox "Control Type is " & TypeName(Ctrl.Object)
        x = Ctrl.Object.Caption
        If Err <> 0 Then
            MsgBox TypeName(Ctrl.Object) & " controls do not have a Caption"
        Else
            MsgBox "Caption is " & Ctrl.Object.Caption
        End If
    Next Ctrl
End Sub
 

Forum statistics

Threads
1,144,734
Messages
5,725,983
Members
422,652
Latest member
Elnene1

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
Top