Artashes
06-15-2012, 01:47 AM
Hi All,
I am trying get the click events of a label ("lblCmdCancel") created on a frame, but unsuccessful. What am I doing wrong?
Here is the code:
Option Explicit
Private WithEvents lblCmdCancel As MSForms.Label
Private Sub CommandButton1_Click()
Dim frmMain As MSForms.Frame
Set frmMain = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Frame.1").Object
With frmMain
.Caption = ""
.BorderStyle = fmBorderStyleSingle
.BorderColor = &H80000006
.Width = 164
.Height = 128
' Some code here ....
Set lblCmdCancel = .Controls.Add("Forms.Label.1", "lblCmdCancel", True)
With lblCmdCancel
.BackColor = &H80000000
.BorderStyle = fmBorderStyleSingle
.Left = 84
.Top = 102
.Width = 72
.Caption = "Cancel"
.TextAlign = fmTextAlignCenter
MsgBox .Name
End With
End With
End Sub
Private Sub lblCmdCancel_Click()
MsgBox "Clicked!"
End Sub
I am trying get the click events of a label ("lblCmdCancel") created on a frame, but unsuccessful. What am I doing wrong?
Here is the code:
Option Explicit
Private WithEvents lblCmdCancel As MSForms.Label
Private Sub CommandButton1_Click()
Dim frmMain As MSForms.Frame
Set frmMain = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Frame.1").Object
With frmMain
.Caption = ""
.BorderStyle = fmBorderStyleSingle
.BorderColor = &H80000006
.Width = 164
.Height = 128
' Some code here ....
Set lblCmdCancel = .Controls.Add("Forms.Label.1", "lblCmdCancel", True)
With lblCmdCancel
.BackColor = &H80000000
.BorderStyle = fmBorderStyleSingle
.Left = 84
.Top = 102
.Width = 72
.Caption = "Cancel"
.TextAlign = fmTextAlignCenter
MsgBox .Name
End With
End With
End Sub
Private Sub lblCmdCancel_Click()
MsgBox "Clicked!"
End Sub