Take the 2-minute tour ×

How can you insert text into a TextBox at the current cursor position?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Text can be inserted at the current cursor position of a TextBox by setting SelText to a string:

TextBox1.SelText = "text to be inserted"
share|improve this answer
Obviously I read your question thoroughly; just quick blink. But I think I gave you an idea as on what to search for ... All the time I was thinking you needed cursor position only... :( –  salih0vicX Nov 17 '12 at 1:36

Let's assume your text box is named: txtTitle:

With txtTitle
   .SelStart = .SelLength 'SelStart will place cursor at the last selected character
End With


txtTitle.SelStart = 7 'This will place cursor after 7th character

EDIT: Just for the clarification: SelLength will return 0 if no character has been selected and than you can use SelStart to get current position. This is what you should test:

Dim iPos As Long
With txtTitle
  If .SelLength = 0 Then
    iPos = .SelStart
    iPos = .SelStart + .SelLength
  End If
  Debug.Print "The current cursor position in " & .Name & " is: " & iPos & " :-)"
End With
share|improve this answer
I don't need to determine the current cursor position. I want to be able insert text programmatically at the current position. I need the equivalent of .NET's textBox1.Text = textBox1.Text.Insert(currentPosition, insertText); –  CJ7 Nov 17 '12 at 1:09

Your Answer


