RAYLWARD102
Well-known Member
- Joined
- May 27, 2010
- Messages
- 529
I already dynamically create, many msForms.Labels on a Userform, with events; I know how to do that exceptionally well.
When it comes to replicating that process to my worksheets; I'm totally lost.
From the controls toolbox in excel, I see that I can manually add a forms or active label to my worksheet. I've sort of figured out how to create a label on the worksheet, using vba, but cannot seem to code vba to link the label to events like click. First off, do the Form labels work same as in user forms as the worksheet?
Here is my attempt at creating a worksheet label via code but totally unable to link to click event. Errors at "Set c1.test = oleobj"
Here is how I successfully code a label to a user form (don't need help with this)
When it comes to replicating that process to my worksheets; I'm totally lost.
From the controls toolbox in excel, I see that I can manually add a forms or active label to my worksheet. I've sort of figured out how to create a label on the worksheet, using vba, but cannot seem to code vba to link the label to events like click. First off, do the Form labels work same as in user forms as the worksheet?
Here is my attempt at creating a worksheet label via code but totally unable to link to click event. Errors at "Set c1.test = oleobj"
Code:
Sub testingout()
Dim oleobj As OLEObject
Set mem1 = New Collection
Set oleobj = ActiveSheet.OLEObjects.Add("Forms.Label.1")
With oleobj
.Height = 30
.Width = 30
.Left = 240.75
.Top = 169.5
.Name = "bob"
Set c1 = New Class1
Set c1.test = oleobj
mem1.Add Item:=c1, Key:=.Name
End With
End Sub
class1 module decalred as
Public WithEvents test As OLEObject
Here is how I successfully code a label to a user form (don't need help with this)
Code:
Set LAB = myForm.Controls.Add("Forms.Label.1")
With LAB
.Caption = "some caption goes here:"
.Height = h
.Width = 100
.Left = 10
.Top =10
.Font.Size = .Height * 0.6
.Name = "somecontrolname"
.SpecialEffect = fmSpecialEffectFlat
.BackColor = vbWhite
.BackStyle = fmBackStyleOpaque
.ForeColor = vbBlue
.TextAlign = fmTextAlignCenter
Set C1 = New PlatformControls
Set C1.test = LAB
Mem1.Add Item:=C1, Key:=.Name
End With
Class looks like:
Public WithEvents test As msforms.Label
Private Sub test_Click()
MsgBox "yo!"
End Sub