View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Fred Holmes Fred Holmes is offline
external usenet poster
 
Posts: 112
Default Using code to create a control on an Excel userform

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