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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select words between two points

Status
Not open for further replies.

SetBuilder

Programmer
May 2, 2001
20
US
In, VB, how can I select a variable number of words between two points. What I want to do is select the parenthesis and everything in between in order to italizize it. So,
(the quick brown fox) becomes (the quick brown fox) italized. I know how to search for the the first "(" and then find the first ")" but I don't know how to set a marker and highlight the inbetween stuff.
 
The following code will do what you want in Word using VBA, however I don't know what application your text is going to be in.

Sub Italics()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "("
.Forward = True
.Wrap = wdFindContinue
.Format = False
End With
Selection.Find.Execute
Selection.Extend
Selection.Extend Character:=")"
Selection.Font.Italic = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
 
Thank you so much. It does exactly what I want. The code should find the next incidence of "(", highlight the words between that and the next ")" and italicize them. Works like a charm. Gold star for you. Thanks for taking the time.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top