Option
Explicit
Private
WithEvents
m_objCtlWrapper
As
VBAProject.CtlWrapper
Private
Sub
CommandButton1_Click()
Dim
i
As
Long
For
i = 1
To
3
With
m_objCtlWrapper.AddControl(
Me
,
"Forms.Label.1"
,
"lblTest"
& Format$(i,
"00"
),
True
)
.Caption =
"Test"
& Format$(i,
"00"
)
.Left = 10
.Width = 50
.Top = 30 * i
End
With
Next
End
Sub
Private
Sub
m_objCtlWrapper_OnClick(
ByVal
Control
As
MSForms.Control)
If
TypeOf
Control
Is
MSForms.Label
Then
MsgBox
"Label_Click {Name: '"
& Control.Name &
"', Caption: '"
& Control.Caption &
"'}"
, vbInformation
End
If
End
Sub
Private
Sub
UserForm_Initialize()
Set
m_objCtlWrapper =
New
VBAProject.CtlWrapper
End
Sub
Private
Sub
UserForm_Terminate()
m_objCtlWrapper.RemoveAll
Set
m_objCtlWrapper =
Nothing
End
Sub