Originally Posted by
gibbo1715
is it possible to do the same kind of loop for this bit of code to cover all 9 checkboxes from one piece of code?
Private Sub CheckBox1_Click()
Dim objCkBox As Object
If Not mBarEvents Then
mBarEvents = True
Me.OLEObjects("CheckBox1").Object.Enabled = False
Application.ActiveWorkbook.RefreshAll
Range("D2").Select
mBarEvents = False
End If
End Sub
You need a pseudo-control array for this.
First add a class module, rename it clsActiveXEvents, and add this code, suitably adjusted to what you want to do
Option Explicit
Public WithEvents mCheckboxes As MSForms.CheckBox
Private Sub mCheckboxes_Click()
Dim iCb As Long
If mCheckboxes.Value Then
MsgBox mCheckboxes.Caption & " turned on"
Else
MsgBox mCheckboxes.Caption & " turned off"
End If
End Sub
and put this code in the worksheet with the checkboxes
Option Explicit
Dim mcolEvents As Collection
Private Sub Worksheet_Activate()
Dim cCBEvents As clsACtiveXEvents
Dim shp As Shape
Set mcolEvents = New Collection
For Each shp In Me.Shapes
If shp.Type = msoOLEControlObject Then
If TypeOf shp.OLEFormat.Object.Object Is MSForms.CheckBox Then
Set cCBEvents = New clsACtiveXEvents
Set cCBEvents.mCheckboxes = shp.OLEFormat.Object.Object
mcolEvents.add cCBEvents
End If
End If
Next
End Sub