You say you cannot use ActiveX, but your code is ActiveX events. MSForms.Checkboxes don't have events. With forms controls, you assign a macro to the control. You can assign the same macro to multiple controls and use Application.Caller
to determine which control called it.
Sub CheckBoxClicked()
Dim chkClicked As CheckBox
Dim chkOther As CheckBox
Set chkClicked = Sheet1.CheckBoxes(Application.Caller)
If chkClicked.Enabled Then
If Application.Caller = "Check Box 1" Then
Set chkOther = Sheet1.CheckBoxes("Check Box 2")
Else
Set chkOther = Sheet1.CheckBoxes("Check Box 1")
End If
chkOther.Value = False
chkOther.Enabled = False
End If
End Sub
This goes in a standard module, not the sheet module.
Checkbox
is deprecated, but still works for me. You can do the same thing using the non-deprecated Shape
object.
Sub CheckBoxClicked()
Dim chkClicked As Shape
Dim chkOther As Shape
Set chkClicked = Sheet1.Shapes(Application.Caller)
If chkClicked.OLEFormat.Object.Enabled Then
If Application.Caller = "Check Box 1" Then
Set chkOther = Sheet1.Shapes("Check Box 2")
Else
Set chkOther = Sheet1.Shapes("Check Box 1")
End If
chkOther.OLEFormat.Object.Value = False
chkOther.OLEFormat.Object.Enabled = False
End If
End Sub
Edit
If you only care about disabling Check Box 2 when Check Box 1 is clicked, the code becomes simpler.
Sub CheckBoxClicked()
Dim chkClicked As CheckBox
Dim chkOther As CheckBox
Set chkClicked = Sheet1.CheckBoxes("Check Box 1")
Set chkOther = Sheet1.CheckBoxes("Check Box 2")
If chkClicked.Enabled Then
chkOther.Value = False
chkOther.Enabled = False
End If
End Sub
You would only assign this macro to Check Box 1.