[Excel 2010 VBA] Get events of an object created on a Frame, OLEObjects.

Artashes Arabajyan

New Member
Joined
Jun 15, 2012
Messages
1
Hi All,

I am trying get the click events of a label created on a frame, but unsuccessful. What am I doing wrong?

Here is the code:
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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,155
Messages
6,170,405
Members
452,325
Latest member
BlahQz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top