Microsoft Office Tutorials and References
In Depth Information
Class Modules for Embedded Objects
ReDim Preserve TxtGroup(1 To intCounterTextBox)
Set TxtGroup(intCounterTextBox).TxtGroup = ctl
End If
Next ctl
End Sub
clAss ModulEs for EMBEddEd oBjEcTs
So far, UserForms have been the backdrop for objects in a class module. You can also create a class
of objects embedded on worksheets, such as charts, pivot tables, and ActiveX controls. In the case of
ActiveX controls, it’s worth mentioning a syntax difference when referring to them.
Suppose you have an unknown number of CommandButtons on Sheet1 and you want to create a class
module to determine which button was clicked, without having to program every CommandButton’s
Click event. This example of code in a class module named Class1 demonstrates how to extract the
name, caption, and address of the cell being touched by the top-left corner of the CommandButton
object. Figure 21-6 shows the Message Box that appears when you click one of the CommandButtons.
figurE 21-6
Public WithEvents cmdButtonGroup As CommandButton
Private Sub cmdButtonGroup_Click()
MsgBox _
“Hello, my name is ‘’” & _
cmdButtonGroup.Name & “‘’.” & vbCrLf & _
“My caption is ‘’” & _
cmdButtonGroup.Caption & “‘’.” & vbCrLf & _
“My top left corner is set in cell “ & _
cmdButtonGroup.TopLeftCell.Address(0, 0) & “.”, _
64, “You just clicked me, here’s my info :”
End Sub
Search JabSto ::

Custom Search