Like this, useform code:
Private LabelCollection As Collection
Private Sub UserForm_Click()
Dim lb As CLabelEvents
Set LabelCollection = New Collection
For n = 1 To (25 * 15)
Set tile = Me.Controls.Add("forms.label.1")
With tile
With Sheets("Align")
oRow = n + 1
tile.Name = .Cells(oRow, 2).Value
tile.Tag = "RAG"
ColOff = Left(tile.Name, InStrRev(tile.Name, "_") - 1)
ColOff = Right(ColOff, Len(ColOff) - InStr(ColOff, "_"))
RowOff = Right(tile.Name, Len(tile.Name) - InStrRev(tile.Name, "_"))
If (Val(ColOff) > IndNum) Or (Val(RowOff) > LocNum) Then
tile.Visible = False
Else
tile.Visible = True
tile.BackStyle = 1
tile.Left = .Cells(oRow, 3).Value
tile.Top = .Cells(oRow, 4).Value
tile.Width = 20
tile.Height = 20
tile.BorderStyle = 1
tile.BorderColor = RGB(255, 255, 255)
tile.ZOrder msoBringToFront
' tile.OnAction = "TileZoom"
ReDim Preserve TileArray(1 To n)
End If
End With
End With
Set lb = New CLabelEvents
Set lb.lb = tile
LabelCollection.Add lb
Next n
End Sub
Class Code - Class is named CLabelEvents
Private WithEvents m_objlb As msforms.Label
Public Property Get lb() As msforms.Label
Set lb = m_objlb
End Property
Public Property Set lb(objlb As msforms.Label)
Set m_objlb = objlb
End Property
Private Sub m_objlb_Click()
MsgBox m_objlb.Caption
End Sub
Bookmarks