Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I create up a stock control system in Excel? Sharon Excel Discussion (Misc queries) 1 July 13th 06 06:51 PM
Userform control ZMore Excel Programming 1 March 5th 04 11:34 PM
Create Custom Control thru Code? Greg Bloom Excel Programming 1 October 13th 03 09:21 PM
Control code behavior with userform ? steve Excel Programming 0 July 30th 03 05:01 PM
UserForm Control Richard Choate Excel Programming 0 July 16th 03 06:50 PM


All times are GMT +1. The time now is 10:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"