Thanks Andreas,
I made the change but doesn't seem to work either.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a textbox with a verticals scrollbar.
I want the scroll bar to remain at the top at start.
So that when users click inside the text box, it doesn't scroll to the bottom of the text, which is what is currently happening.
'
I found this online but don't know how to implement:
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
Not sure this works or where to find the Initialize event...
If someone can help,
Thanks,
Faycal
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Thanks Andreas,
I made the change but doesn't seem to work either.
Make a new Excel file
Open the VBA editor
Insert a Userform
Add 2 Textboxes
Paste in the code below
Run the form
Works for me.
Andreas.
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
With TextBox2
.Text = sSample
.SelStart = 0
.MultiLine = True
.ScrollBars = fmScrollBarsVertical
.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
.SetFocus
.SelStart = 0
End With
With TextBox1
.Text = sSample
.MultiLine = True
.ScrollBars = fmScrollBarsVertical
.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
.SetFocus
.SelStart = 0
End With
End Sub
Thanks Andreas,
I will try that today.
Best,
Faycal
I am still trying to get my textbox to scroll to top when I initially click inside the textbox.
I have the following code ,
It still doesn't work,
When I use the .setFocus it comes up with an error in the code saying "Object doesn't support this property or method".
Private Sub UserForm_Initialize()
TextBox1.SetFocus
TextBox1.SelStart = 0
End Sub
If someone can help troubleshoot.
Thanks,
Faycal
Faycal,
I think you have to use the On_Enter event:
Private Sub TextBox1_Enter()
Me.TextBox1.SelStart = 0
End Sub
Then the scrollbar doesn't display until going to lines initial outside the textbox.
Jan