Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba code to access checkboxes within groups?

Hi all,
I have a question about the correct way to access the value of a
checkbox that has been 'grouped' with other checkboxes.

I have Excel 2003, on a windows XP sp2 platform.

I have a spreadsheet that has a number of checkboxes that have been
grouped to form a survey. The checkboxes were added using the control
toolbar.

There are about 30 checkboxes, grouped 5 per question, so there are 6
groups.

How can I use VBA to access the value of each checkbox?

I can do it if I first ungroup the checkboxes, then interrogate each
checkbox individually. I would rather not modify the spreadsheet!

Here is how I ungroup the checkboxes:
(straight from the MS example)

' ungroup the group boxes....
With ActiveSheet.Shapes
For s = .Count To 1 Step -1
If .Item(s).Type = msoGroup Then .Item(s).Ungroup
Next s
End With

And here is some code that lets me check each value...

For Each myCheckbox In Worksheets("mySheet").OLEObjects
If InStr(myCheckbox.name, "CheckBox") 0 Then
MsgBox ("I am "+myjunk.name)
If myCheckbox.Object.Value = False Then
' do something
Else
' do something else
End If
End If
Next

Any ideas on how to do this more cleanly?

Regards, Brad

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default vba code to access checkboxes within groups?

You might try accessing the value of the group. For ex. if the group name
was grpCheckBoxes1 the code would be grpCheckBoxes1.Value. This should get
you the value you are looking for.


" wrote:

Hi all,
I have a question about the correct way to access the value of a
checkbox that has been 'grouped' with other checkboxes.

I have Excel 2003, on a windows XP sp2 platform.

I have a spreadsheet that has a number of checkboxes that have been
grouped to form a survey. The checkboxes were added using the control
toolbar.

There are about 30 checkboxes, grouped 5 per question, so there are 6
groups.

How can I use VBA to access the value of each checkbox?

I can do it if I first ungroup the checkboxes, then interrogate each
checkbox individually. I would rather not modify the spreadsheet!

Here is how I ungroup the checkboxes:
(straight from the MS example)

' ungroup the group boxes....
With ActiveSheet.Shapes
For s = .Count To 1 Step -1
If .Item(s).Type = msoGroup Then .Item(s).Ungroup
Next s
End With

And here is some code that lets me check each value...

For Each myCheckbox In Worksheets("mySheet").OLEObjects
If InStr(myCheckbox.name, "CheckBox") 0 Then
MsgBox ("I am "+myjunk.name)
If myCheckbox.Object.Value = False Then
' do something
Else
' do something else
End If
End If
Next

Any ideas on how to do this more cleanly?

Regards, Brad


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
Access Groups from IE? Linda RQ[_2_] New Users to Excel 4 April 26th 10 07:00 AM
Checking and Unchecking CheckBoxes in code Ayo Excel Discussion (Misc queries) 0 April 3rd 09 08:41 PM
checkboxes and code Soniya[_4_] Excel Programming 3 April 24th 05 01:08 PM
Adding checkboxes via code to a workheet Stef Excel Programming 0 February 1st 05 02:51 PM
Making All Checkboxes Run the Same Code MT DOJ Help Desk[_3_] Excel Programming 5 May 12th 04 06:24 AM


All times are GMT +1. The time now is 04:06 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"