View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
jkrons jkrons is offline
external usenet poster
 
Posts: 19
Default Looping through checkboxes

On 6 Jan., 16:47, John Coleman wrote:
On Jan 6, 8:59*am, jkrons wrote:

I have the line of code


Sheets(1).OLEObjects("CheckBox1").Object.Value = True


that works great, but how do I loop through all the checkboxes in my
sheet with something like this


For Each cb In Sheets(1).OLEObjects.CheckBoxes
Sheets(1).OLEObjects(cb.Name).Object.Value = True


I get a runtime error 430 Object doesn't support this property or
method.


How do I loop through the checkboxes?


I don't know of any way to do this directly. If you keep the default
control names (or consistently adopt a naming convention) you could
use the like operator:

Sub test()
* * Dim control As OLEObject

* * For Each control In Sheets(1).OLEObjects
* * * * If control.Name Like "CheckBox*" Then MsgBox control.Name
* * Next

End Sub

hth


Thank you. That helped.

Jan