|
クラスで考えてみました。
'**クラスモジュール****************************************
Private WithEvents pr_optButton As MSForms.OptionButton
'==============================================
Public Property Get myButton() As MSForms.OptionButton
Set myButton = pr_optButton
End Property
'==============================================
Public Property Let myButton(ByVal optNew As MSForms.OptionButton)
Set pr_optButton = optNew
End Property
'==============================================
Private Sub Class_Terminate()
Set pr_optButton = Nothing
End Sub
'==============================================
Private Sub pr_optButton_Change()
With pr_optButton
If .Value = True Then
.BackColor = RGB(176, 196, 222)
.BackStyle = 1
Else
.BackStyle = 0
End If
End With
End Sub
'**フォームモジュール****************************************
Private clsButton(15) As clsTest
'==============================================
Private Sub UserForm_Initialize()
Dim i As Long
For i = 1 To 4
Set clsButton(i) = New clsTest
clsButton(i).myButton = Me.Controls("OptionButton" & i)
Next i
End Sub
'==============================================
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim i As Long
For i = 1 To 4
Set clsButton(i) = Nothing
nexti
End Sub
どないでしょう?
|
|