Microsoft Office Tutorials and References
In Depth Information
Try It
15.
Declare an Integer type variable that will help loop through the five OptionButtons that will
become a part of the class module:
Dim intCounterOptionButton As Integer
16.
Open a For Next loop to loop through the five OptionButtons:
For intCounterOptionButton = 1 To 5
17.
Set each of the five OptionButtons as members of the OptGroup class:
Set optButtons(intCounterOptionButton).OptGroup = _
Controls(“OptionButton” & intCounterOptionButton)
18.
Continue and close the For Next loop with the Next statement:
Next intCounterOptionButton
19.
All of your coding is complete. The entire UserForm module contains the following
VBA code:
Option Explicit
Dim optButtons(1 To 5) As New Class1
Private Sub UserForm_Initialize()
Dim intCounterOptionButton As Integer
For intCounterOptionButton = 1 To 5
Set optButtons(intCounterOptionButton).OptGroup = _
Controls(“OptionButton” & intCounterOptionButton)
Next intCounterOptionButton
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
20.
Test your class module by showing the UserForm. Press Ctrl+G to open the Immediate
window, type the statement UserForm1.Show , and then press the Enter key.
21.
Click any of the five OptionButtons on the left to display the Message Box that identifies the
name and caption of the OptionButton you click. In Figure 21-13 I clicked OptionButton4,
having the caption Grapes. The OptionButtons on the right side of the UserForm are not
included in the class, and if clicked will not invoke a Message Box.
Search JabSto ::




Custom Search