Active x textbox not increasing in size with additional lines of text

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have an active x text box that will not increase in size for extra lines of text that are added.

I want it to be a set length, 540 and to increase in size downwards when additional lines of text are added.

This is the code that someone helped me with, can someone tell me what I need to change to get it to work please?

Code:
Private Sub TextBox1_Change()
TextBox1.Height = TextBox1.Height
TextBox1.Width = 540
End Sub


Private Sub TextBox1_GotFocus()
  TextBox1.Width = 540
  If TextBox1 = "Please type notes here" Then
    TextBox1 = ""
  End If
End Sub


Private Sub TextBox1_LostFocus()
  TextBox1.Height = TextBox1.Height
  TextBox1.Width = 540
  If TextBox1 = "" Then
    TextBox1 = "Please type notes here"
  End If
End Sub

Thanks guys
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Now with the new code, the text "Please types notes here won't appear when the text box is empty. here is the new code.

Code:
Private Sub TextBox1_Change()
    Dim hBox As Double, h As Double, h5 As Double, H6 As Double
    h5 = Me.Rows(5).RowHeight
    H6 = Me.Rows(6).RowHeight
    
    With Me.Shapes("TextBox1")
        hBox = .Height
        .Top = Me.Rows(4).Top + 10
    End With
    h = hBox - h5 - H6
    If h > 0 Then
        Me.Rows("7:8").RowHeight = h / 2
    Else
        Me.Rows("7:8").RowHeight = 0
    End If
End Sub

Can someone please help?
 
Upvote 0
I looked at your question but really do not have a good answer for you.

This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Auto resizing can be accomplished thus:

Code:
Private Sub TextBox1_Change()
    Call Size(TextBox1)
End Sub

Private Sub TextBox1_GotFocus()
    Call Size(TextBox1)
End Sub

Private Sub TextBox1_LostFocus()
    Call Size(TextBox1)
End Sub

Private Sub Size(tb As Object)
    With tb
        .AutoSize = True
        .Width = 540
        .EnterKeyBehavior = True
        .MultiLine = True
    End With
End Sub

For clarity, toggling the contents of the textbox is ignored above
 
Last edited:
Upvote 0
That worked for me.
I learned something today.

Auto resizing can be accomplished thus:

Code:
Private Sub TextBox1_Change()
    Call Size(TextBox1)
End Sub

Private Sub TextBox1_GotFocus()
    Call Size(TextBox1)
End Sub

Private Sub TextBox1_LostFocus()
    Call Size(TextBox1)
End Sub

Private Sub Size(tb As Object)
    With tb
        .AutoSize = True
        .Width = 540
        .EnterKeyBehavior = True
        .MultiLine = True
    End With
End Sub

For clarity, toggling the contents of the textbox is ignored above
 
Upvote 0
That is good to know, I will try it when I am back at work tomorrow.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,952
Members
448,535
Latest member
alrossman

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