Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Userform textbox default value and highlighted

In my UserForm, I want to set a default value for my TextBox, that will highlight when focused upon.

Private Sub UserForm_Initialize()

NameTextBox.Value = "Your Name Here"

NameTextBox.SetFocus

End Sub

When this code runs, the cursor should set at the end of the default text, i.e. after "...Here". I want "Your Name Here" to be highlighted so that when the form is generated, the user can start replacing that default/placeholder text.

Can you help me write the code to set default values that are editable?

like image 304
blahblahblah Avatar asked Jan 15 '14 04:01

blahblahblah


1 Answers

This will select all the text in the TextBox:

Private Sub UserForm_Initialize()
With Me.NameTextBox
    .Value = "Your Name Here"
    .SetFocus
    .SelStart = 0
    .SelLength = Len(.Text)
End With
End Sub
like image 74
Doug Glancy Avatar answered Nov 11 '22 11:11

Doug Glancy