Black Dagger
Black Dagger

Reputation: 399

Text box by default shouldnt scroll to the end

My text box in VBA, by default scrolls to the bottom. I dont want this. I want the scroll bar to remain at the top when the userform displays.

Solution?

Upvotes: 2

Views: 5024

Answers (2)

Sacid Karacuha
Sacid Karacuha

Reputation: 21

In the UserForm's Initialize event, you can use textbox1.curline=0

Private Sub UserForm_Initialize()

TextBox1.SetFocus ' to make next line work, first we must set focus on Textbox
TextBox1.CurLine = 0

End Sub

Upvotes: 1

Siddharth Rout
Siddharth Rout

Reputation: 149305

In the UserForm's Initialize event, set the starting point of the cursor to TextBox's start using .SelStart

For example.

Private Sub UserForm_Initialize()
    Dim sSample As String
    Dim i As Long

    For i = 1 To 10
        sSample = sSample & "Blah Blah" & i & vbNewLine
    Next i

    TextBox1.Text = sSample

    '~~> Set to starting point
    TextBox1.SelStart = 0
End Sub

Upvotes: 4

Related Questions