Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Using code to create a control on an Excel userform
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I create up a stock control system in Excel? | Excel Discussion (Misc queries) | |||
Userform control | Excel Programming | |||
Create Custom Control thru Code? | Excel Programming | |||
Control code behavior with userform ? | Excel Programming | |||
UserForm Control | Excel Programming |