This doesn't work because optGroup is not a object.
But you can treat it like one.
Put this in the user forms code module.
The button will toggle the enabled status of all the option buttons whose group name is "xx"
Private Sub CommandButton1_Click()
EnableOptionGroup("xx") = Not (EnableOptionGroup("xx"))
End Sub
Property Get EnableOptionGroup(Name As String) As Boolean
Dim oneControl As MSForms.Control
For Each oneControl In Me.Controls
If TypeName(oneControl) = "OptionButton" Then
If oneControl.GroupName = Name Then
EnableOptionGroup = oneControl.Enabled
Exit Property
End If
End If
Next oneControl
End Property
Property Let EnableOptionGroup(Name As String, EnableValue As Boolean)
Dim oneControl As MSForms.Control
For Each oneControl In Me.Controls
If TypeName(oneControl) = "OptionButton" Then
If oneControl.GroupName = Name Then
oneControl.Enabled = EnableValue
End If
End If
Next oneControl
End Property
You can also use code like
EnableOptionGroup("xx") = False
MsgBox EnableOptionGroup("xx")
If EnableOptionGroup("xx") Then
' code
End If
If no option button has the .GroupName "xx" then EnableOptionGroup("xx") will return False. and setting the value of EnableOptionGroup("xx") will have no effect.
Bookmarks