Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace selected text only

Status
Not open for further replies.

JESTAR

Programmer
Feb 13, 2002
213
GB
How would I use Replace on a textbox to replace only the text that is selected with a new string, instead of Replace replacing every occurence of the string.
 
Use mid statement to split the string at the selstart point. Then, add your new string, and then add the rest of the string, after selstart+sellenght.

text1.text=mid(text1.text, 1, text1.selstart-1) & _
myNewStringToAdd & _
mid(text1.text, text1.selstart + text1.sellength)

Where text1 is the textbox, and myNewStringToAdd is the bit you want to put into the string instead of the highlighted text.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top