Insert a label into a userform In VB

John Caines

Well-known Member
Joined
Aug 28, 2006
Messages
1,155
Office Version
  1. 2019
Platform
  1. Windows
Hello All.
I have VBA open now,,,
I want a pop up to appear when my spreadsheet opens.
I have been told that a userform you can do more with.
So,, I'm in VBA and clicked add userform.
I've managed to insert a picture from the Categorized tab.

Great,, but I'd love to add text to this form,,,
How can I add text whilst in VBA?
I just can't see how to?
I take it it is a Label?

I've managed to get it to work,,as in pop up when the spreadsheet opens, having found code from other posts on the forum etc,, but I just can't see how to add text to the userform when I'm in VBA??? :-(

If someone could please tell me how I can add a text label within this whilst in VBA please.
(I've managed to have inserted a picture fine,,,but no text!! :-( ).
I just really can't see how this is done.

Hope someone can explain it to me,, it's so so annoying,, just can't get it
Many Thanks.
John Caines
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
OK, so you've added a form. That means you've found the IDE [integrated development environment]. While in the IDE, select the 'ToolBox' icon just below the menu and click the 'Label' control. Then click on your form in the IDE and the label should get added.

Immediately after adding the Label, hit the 'F4' button on your keyboard to display the 'Properties' window in your IDE. It should show the properties for whatever contol is currently selected on your form....in your case, the Label.

Change the 'Caption' property to whatever text you want to appear in the label on your form.
 
Upvote 0
John

In design mode you can set the Caption property of the label.

However you could also do that in the userform's Initialize event, which might give you a little more flexibility on what to display.

For example you could include the date/time.
Code:
Private Sub UserForm_Initialize()
        Label1.Caption = "It's " & Time() & " on " & Date() & "."
End Sub
Sorry for the not very exciting example, all I could think of.:)
 
Upvote 0
Many many thanks for both your replies!
Brilliant...
Thing is,, I just can't tell you what I was doing wrong.
I was trying I think to use the insert user form from the ribbon on the main spreadsheet area,, not within VBA.
Maybe this was the problem.
Every time I clicked on the Label and tried to drag it over my userform, it didn't 'Stick',, it just wouldn't accept it.!!
it was driving me crazy....
a big thankyou to you both,,,, now I need a cup of tea,, and will alter my userform!!! :-)
A very very grateful
John Caines
 
Upvote 0
Just seeing Now If I can alter the text,, so it is VERTICAL,,,, can't see it...

I see in the Label TextAlign & WordWrap,,,Width,,,
But No way to alter the text to display Vertically??
Can it be done?
Or is this a limitation within the label of a UserForm?


Many Thanks
John Caines
 
Upvote 0
John

It can't really be done that simply with a standard label, there's is no option for that sort of thing.

You could resize the label to make it only one character wide, but doing that sort of thing is fiddly.

It can be done in code but again that's not too straightforward.

Quite a bit of calulating to work out what the width/height should be based on the font, length ot text etc...

What is it you are trying to do exactly?
 
Upvote 0
Hi Norie,,
It's ok,, I can leave it,,

What I'm trying to do is create a pop up that is timed,, (It shows for 3-4 seconds when the spreadsheet is opened).
It will have some text in it,, also a picture,,,

Just a kind of welcome screen if you like,,,,
And on close also,, a goodbye screen.


I've managed to dig out code from various internet/forums etc,, so its working now,,,
I just wanted to "Polish it off",,, make it look a bit more professional,,,

Adnd thought some vertical Text would be quite effective in the popup (Sorry Userform :-)) window.
Maybe something like;

T
R
A
D
E
R

That was all. In A Cambria Font,, size 14.

But hey,, seems like a hard job,, so no worries.
many thanks for your reply
All the Best
John Caines
 
Upvote 0
John

Why not just create/edit the image so it includes the text you want in it?

Even the simplest graphic packages allow you to do what, and obviously with some of them you'll have a whole load of effects, fonts etc at your disposal.

Obviously that wouldn't work if you did want to make the text dynamic in some way.

By the way for the time thing take a look at Application.OnTime, which you could use to close the userform after a set period of time.
 
Upvote 0
Great Idea Norie,,,
I never thought of that.

Actually, the image I have inserted at the moment is a bit lame,
It needs some work doing to it.

I will do this.

Good Idea! :-)

All the best
John Caines
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top