SteveInAlabama
Board Regular
- Joined
- Aug 22, 2002
- Messages
- 94
I have a worksheet with several dozen embedded checkboxes. They are Form Controls, not ActiveX controls. I want to generate a Click event every time one of the checkboxes is clicked. I can find each checkbox in the Activesheet.Shapes collection as a Shape object, but I cannot convert the Shape object to a MSForms.CheckBox object. No matter what I've tried, I still get a Type mismatch error on the line "Set chkBoxEvent.mCheckbox = shp.OLEFormat.Object".
Here is my CCheckBoxEvent class:
Then in a standard Module, I have the following method:
Thanks in advance!
Here is my CCheckBoxEvent class:
Code:
Option Explicit
Public WithEvents mCheckbox As MSForms.CheckBox
Private Sub mCheckbox_Click()
MsgBox "Event generated"
End Sub
Then in a standard Module, I have the following method:
Code:
Option Explicit
Dim chkBoxCollection As Collection
Sub Set_All_ChkBoxes()
Dim chkBoxEvent As CCheckBoxEvent
Dim shp As Shape
Set chkBoxCollection = New Collection
For Each shp In ActiveSheet.Shapes
If shp.Type = msoFormControl Then
If shp.FormControlType = xlCheckBox Then
Set chkBoxEvent.mCheckbox = shp.OLEFormat.Object
chkBoxCollection.Add chkBoxEvent
End If
End If
Next shp
End Sub
Thanks in advance!