The code below, sent by Luiz Vieira, creates Labels dynamically and a click-handling function for each Label.
I would like to know how to use the Click event to remove the Labels that were created dynamically.
Creating Labels:
Dim Labels() As New LabelHandler
Private Sub CriaLabels(ByVal QuantidadeDeLabels As Integer)
Dim i As Integer
Dim Label As Control
ReDim Labels(0 To QuantidadeDeLabels - 1)
For i = 0 To QuantidadeDeLabels - 1
Set Label = Me.Controls.Add("Forms.Label.1", "NewLabel" & i)
With Label
.Caption = "NewLabel" & i
.Top = 50 * i
.Left = 50
End With
Set Labels(i).Ctrl = Label
Next i
End Sub
Click treatment function in the class module:
Public WithEvents Ctrl As MSForms.Label
Private Sub Ctrl_Click()
MsgBox "Você clicou no label de nome " & Ctrl.Name
End Sub