ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm TextBox with fixed Width and dynamic Height (https://www.excelbanter.com/excel-programming/355084-userform-textbox-fixed-width-dynamic-height.html)

Soniya[_4_]

UserForm TextBox with fixed Width and dynamic Height
 
Hello,

Can we have a multi line TextBox in a Userform with fixed width but the
height adjusting according to the length of text? Say if the textbox
contains text to be fit in five lines then adjust the height
accrdingly? also with a maximum height fixed, so that it may not be
more than the height of the userfom itself.

Thanks


Helmut Weber[_2_]

UserForm TextBox with fixed Width and dynamic Height
 
Hi Soniya,

like this:

Private Sub TextBox1_Change()
TextBox1.Width = 100
' to restrict autosize to vertical
If TextBox1.Height 75 Then
TextBox1.Height = 75
TextBox1.AutoSize = False
End If
End Sub


plus
multiline = true
autosize = true
wordwrap = true

Unfortunately, when typing some lines of text,
the first line vanishes temporarily,
but reappears when the textbox looses focus.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Just fooling around with Excel a bit

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Bob Phillips[_6_]

UserForm TextBox with fixed Width and dynamic Height
 
You could play around a bit with it, by adjusting the height by the number
of characters, but I doubt that you can be totally accurate as it depends
upon where the word breaks.

Private Sub TextBox1_Change()
With Me.TextBox1
.Height = Application.Min(Me.Height - 32, (Int(Len(.Text) /
Int(.Width / 4.7)) + 1) * 18)
End With
End Sub

should get you started on the idea, but you will need to play with the
variables to suit.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Soniya" wrote in message
oups.com...
Hello,

Can we have a multi line TextBox in a Userform with fixed width but the
height adjusting according to the length of text? Say if the textbox
contains text to be fit in five lines then adjust the height
accrdingly? also with a maximum height fixed, so that it may not be
more than the height of the userfom itself.

Thanks





All times are GMT +1. The time now is 09:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com