Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Looping through checkboxes

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Looping through checkboxes

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Looping through checkboxes

For Each mychkbox In wks.CheckBoxes
With mychkbox
.Value = True
End With
Next mychkbox


Gord


On Fri, 6 Jan 2012 05:59:54 -0800 (PST), 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Looping through checkboxes

On Jan 6, 11:36*am, Gord Dibben wrote:
For Each mychkbox In wks.CheckBoxes
* * * * With mychkbox
* * * * * .Value = True
* * * * End With
* * Next mychkbox

Gord


That seems to work for form controls but not ActiveX controls. It also
seems to be poorly documented (e.g. doesn't appear in the object
browser for worksheet methods) so thanks for pointing it out.



On Fri, 6 Jan 2012 05:59:54 -0800 (PST), 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?- Hide quoted text -


- Show quoted text -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Looping through checkboxes

You are correct John.

Forms only............was not paying attention(usual state).

Did not notice OP required code on Activex Checkboxes.

The code I posted was part of a larger set by Dave Peterson for
changing Forms checkbox linked cells.


Gord

On Fri, 6 Jan 2012 09:09:37 -0800 (PST), John Coleman
wrote:

On Jan 6, 11:36*am, Gord Dibben wrote:
For Each mychkbox In wks.CheckBoxes
* * * * With mychkbox
* * * * * .Value = True
* * * * End With
* * Next mychkbox

Gord


That seems to work for form controls but not ActiveX controls. It also
seems to be poorly documented (e.g. doesn't appear in the object
browser for worksheet methods) so thanks for pointing it out.



On Fri, 6 Jan 2012 05:59:54 -0800 (PST), 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?- Hide quoted text -


- Show quoted text -

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through checkboxes TomK76 Excel Programming 1 September 11th 09 03:47 PM
Looping Checkboxes in Worksheet Lin Excel Programming 3 November 12th 08 09:44 PM
Looping through a group of checkboxes asdfasdf Excel Programming 9 October 13th 05 02:04 AM
Looping Checkboxes on Worksheet Robbyn Excel Programming 2 August 7th 05 09:09 PM
Checkboxes to spreadsheet using a looping macro Eddie[_5_] Excel Programming 0 September 8th 04 11:04 AM


All times are GMT +1. The time now is 08:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"