+ Reply to Thread
Results 1 to 3 of 3

UserForm TextBox with fixed Width and dynamic Height

  1. #1
    Soniya
    Guest

    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


  2. #2
    Helmut Weber
    Guest

    Re: 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"

  3. #3
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1