search for next word

  • Thread starter Partha Mandayam
  • Start date
P

Partha Mandayam

I want to find a particular word in a document and then find the immediate
next word and store it in a variable. How can I do this?
 
M

Mark Tangard

Partha said:
I want to find a particular word in a document and then find the immediate
next word and store it in a variable. How can I do this?

Dim myvar As String
With Selection.Find
.Text = "YourWordHere"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWildcards = False
.Execute
End With
Selection.MoveRight Unit:=wdWord, Count:=1
myvar = Selection.Words(1).Text
 
P

Partha Mandayam

Thanks

Mark Tangard said:
Dim myvar As String
With Selection.Find
.Text = "YourWordHere"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWildcards = False
.Execute
End With
Selection.MoveRight Unit:=wdWord, Count:=1
myvar = Selection.Words(1).Text

--
Mark Tangard, Microsoft Word MVP
Please reply only to the newsgroup, not by private email.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top