Setting Userform Label width to fit text

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
I need to set the width of the label to auto fit the caption text. So from my research the text is in points and the width is in twips. So I need to get the length of the text string in twips to set the label width. Any ideas?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try something like this.
Label1.Width = 500 is just to make sure the text won’t get wrapped to multiple lines.
Type some words in textbox1 then hit the command button



Please use Code Tags when posting a code. Like this: [CODE ]Your Code Here[/ CODE]
Code:
[B][COLOR=Royalblue]Private[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B] CommandButton1_Click[B]()[/B]
    Label1.AutoSize [B]=[/B] [B][COLOR=Royalblue]False[/COLOR][/B]
    Label1.Width [B]=[/B] [B][B][COLOR=crimson]500[/COLOR][/B][/B]
    Label1.Caption [B]=[/B] TextBox1
    Label1.AutoSize [B]=[/B] [B][COLOR=Royalblue]True[/COLOR][/B]
    Label1.Height [B]=[/B] [B][B][COLOR=crimson]20[/COLOR][/B][/B]
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]

 
Upvote 0
You're welcome & thanks for replying. :)


And you can also click ‘Thank you for posting this’ and ‘Like this post’ button in the post that you like.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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