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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Like this:

Code:
Sub Test()
    Dim Ctrl As OLEObject
    For Each Ctrl In ActiveSheet.OLEObjects
        MsgBox Ctrl.Name
    Next Ctrl
End Sub
 
Upvote 0
Did you check the properties of the object in question? if 'caption' isn't one of them, check for a synonym.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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