Code: Select all
Private Sub UserForm_Initialize()
With textboxExample
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Chris
Code: Select all
Private Sub UserForm_Initialize()
With textboxExample
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Code: Select all
Private Sub UserForm_Initialize()
With Me.TextBoxExample
.Text = "Hello World"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Code: Select all
Private Sub CommandButton1_Click()
MsgBox "SelText=" & Me.TextBox1.SelText
Me.Hide
End Sub
Private Sub UserForm_Initialize()
With Me.TextBox1
.Text = "hello"
.SelStart = 0
.SelLength = Len(.Text)
End With
Me.CommandButton1.SetFocus
End Sub
If the form was initialized and hidden, you may need to move your code to the activate event.Cah wrote:But the results are inconsistent. If I change the value of the text just before calling up the form then this doesn't work and the text isn't highlighted.
Thanks, moving the code to the activate event did the trick.jscher2000 wrote:If the form was initialized and hidden, you may need to move your code to the activate event.