A variation on Pauls class module would be for the OptionButton_Click event in the Class module to call a particular routine in the userfoms code module.
Create a class module, change its name to clsFrameOptionButton and put this code in its code module
' in clsFormOptionButton code module
Public WithEvents OptionButton As MSForms.OptionButton
Dim myColl As Collection
Private Sub OptionButton_Click()
On Error Resume Next
CallByName UFParent, OptionButton.Parent.Name & "OptionButton_Click", VbMethod
On Error GoTo 0
End Sub
Private Function UFParent() As Object
Set UFParent = OptionButton
On Error Resume Next
Do
Set UFParent = UFParent.Parent
Loop Until Err
On Error GoTo 0
End Function
Private Sub Class_Initialize()
Set myColl = New Collection
myColl.Add Item:=Me
End Sub
Then in the user form, in the Initialize event, create an instance of clsFormOptionButton for each OptionButton in the user form. Note that you don't have to store them anywhere, they are self-perpetuating.
If you want a particular Frame's option buttons to run a routine all you have to do is write a Public Sub, changing the name of the frame to match.
Public Sub Frame1OptionButton_Click()
' code
End Sub
Note that this must be declared a Public sub. Also note that the frame's ActiveControl will be the option button that was clicked. (this maybe different than the Userform's .ActiveControl)
In the attached workbook and user form you will see that the option buttons don't have to be in a form, they can be directly in that user form or they could be in the Page of a MultiPage. It all depends on the existence (or not) of the Public Sub (container's name)OptionButton_Click() code.
In the attached, option buttons in Frame1 or Frame2 or directly in the Userform each have a different event. However the option buttons in Frame3 aren't playing.
' in userform code module
Private Sub UserForm_Initialize()
Dim newFOB As clsFormOptionButton
Dim oneControl As MSForms.Control
For Each oneControl In Me.Controls
If TypeName(oneControl) = "OptionButton" Then
Set newFOB = New clsFormOptionButton
Set newFOB.OptionButton = oneControl
End If
Next oneControl
Set newFOB = Nothing
End Sub
Public Sub Frame1OptionButton_Click()
MsgBox Frame1.ActiveControl.Name & " clicked"
End Sub
Public Sub Frame2OptionButton_Click()
MsgBox Frame2.ActiveControl.Name & " in Frame2 was clicked"
End Sub
Public Sub Userform1OptionButton_Click()
MsgBox "You clicked a userform's direct child option button"
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub