tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
The following code works for ActiveX checkboxes:
ThisWorkbook:
ClsCheckBoxEvent:
How can I adapt it so it works for Forms checkboxes? (I don't mean a checkbox on a userform but a checkbox under Developer -> Insert - Forms Controls).
Thanks
ThisWorkbook:
Code:
Option Explicit
Dim CheckBoxesColl As Collection
Private Sub Workbook_Open()
Dim CheckBoxHandler As ClsCheckBoxEvent
Set CheckBoxesColl = New Collection
Dim MyShp As Shape
For Each MyShp In Sheet1.Shapes
With MyShp
If .Type = msoOLEControlObject Then
With .OLEFormat.Object
If TypeOf .Object Is MSForms.CheckBox Then
Set CheckBoxHandler = New ClsCheckBoxEvent
Set CheckBoxHandler.CheckGroup = .Object
CheckBoxesColl.Add Item:=CheckBoxHandler
End If
End With
End If
End With
Next MyShp
End Sub
ClsCheckBoxEvent:
Code:
Option Explicit
Public WithEvents CheckGroup As MSForms.CheckBox
Private Sub CheckGroup_Click()
Select Case CheckGroup.Caption
Case "CheckBox1"
Select Case CheckGroup.Value
Case True
MsgBox "CheckBox 1 checked"
Case False
MsgBox "CheckBox 1 unchecked"
End Select
Case "CheckBox2"
Select Case CheckGroup.Value
Case True
MsgBox "CheckBox 2 checked"
Case False
MsgBox "CheckBox 2 unchecked"
End Select
End Select
End Sub
How can I adapt it so it works for Forms checkboxes? (I don't mean a checkbox on a userform but a checkbox under Developer -> Insert - Forms Controls).
Thanks