View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Series of check boxes


Steph,
Here is one approach...

'--------------------------------
'Determines the value of the first checkbox on the sheet.
'Sets all checkboxes to the opposite value.
'Uses a "Button" from the forms toolbar.
'The button is captioned "Toggle all CheckBoxes"
'Jim Cone - San Francisco, USA - August 29, 2005

Sub ToggleAll()
Dim Shp As Excel.Shape
For Each Shp In ActiveSheet.Shapes
If Shp.Type = msoFormControl Then
'from the Forms toolbar (not Activex)
If Shp.FormControlType = xlCheckBox Then
If Shp.ControlFormat.Value = 1 Then
Call SetButtonValuesOff
Else
Call SetButtonValuesOn
End If
Exit Sub 'important
End If
End If
Next 'Shp
Set Shp = Nothing
End Sub

'Changes the value of all checkboxes to 1 (checkmarked)
Sub SetButtonValuesOn()
Dim Shp As Excel.Shape
For Each Shp In ActiveSheet.Shapes
If Shp.Type = msoFormControl Then
'from the Forms toolbar (not Activex)
If Shp.FormControlType = xlCheckBox Then
Shp.ControlFormat.Value = 1
End If
End If
Next
Set Shp = Nothing
End Sub

'Changes the value of all checkboxes to 0 (Unchecked)
Sub SetButtonValuesOff()
Dim Shp As Excel.Shape
For Each Shp In ActiveSheet.Shapes
If Shp.Type = msoFormControl Then
'from the Forms toolbar (not Activex)
If Shp.FormControlType = xlCheckBox Then
Shp.ControlFormat.Value = 0
End If
End If
Next
Set Shp = Nothing
End Sub
'-----------------------


"Steph" wrote in message

Hello. I have a list of files in column A that vba opens when the code is
executed. It opens all files listed. I would like to add a check box on
each row that will allow the user to choose which files to print.

I was thinking of using a check box from the forms menu, and having it
populate a column, then have vba loop through and pick all the "yes"'s from
that column. I know how to do that part. BUT, I was hoping for a button at
the top that was a "Select All", and "Deselect All". That part I don't know
how to do. Anyone have any idea on how to accomplish this, and if the
checkbox from the forms menu is the best way to go? Thank you in advance!