Hi Fred,
Try this code.
'---
Dim labTemp As MSForms.Label
Set labTemp = Me.Controls.Add("Forms.Label.1", "MyLabel", True)
With labTemp
.Caption = "Hello World"
.BorderStyle = fmBorderStyleNone
End With
'---
Cheers
Andy
Fred Holmes wrote:
In Visual Basic 6 (not VBA) I can create a control on a UserForm with
working code such as:
Private Sub Form_Load()
Set lblMyLabel = Me.Controls.Add("vb.label", "lblMyLabel", Me)
I'm trying to do the same thing with a userform in VBA in Excel 2003.
Private Sub UserForm_Initialize()
Set lblMyLabel = Me.Controls.Add("vb.label", "lblMyLabel", Me)
With this code included, I get an error message "Invalid Class String"
on the UserForm1.Show statement.
Is it possible in Excel vba to create a control with a Set statement?
What's the correct syntax? Have I omitted some Dim Statement???
I've: Dim lblMyLabel As Label
Thanks,
Fred Holmes
--
Andy Pope, Microsoft MVP - Excel
http://www.andypope.info