Help for Newbie: How to search a document for a string patern and grab the word

B

Billy

Hi

So I need to search a document for this pattern:

"{{some_text_here}}"

and, if/when I find a match, I want to assign that matching text to a
string. I've seen the code to find something (e.g. ActiveDocument.Content.
Find.Execute()), but not anything that can actually grab the text for me.

Any help would be greatly appreciated. Thanks.

BB
 
J

Jean-Guy Marcil

Billy was telling us:
Billy nous racontait que :
Hi

So I need to search a document for this pattern:

"{{some_text_here}}"

and, if/when I find a match, I want to assign that matching text to a
string. I've seen the code to find something (e.g.
ActiveDocument.Content. Find.Execute()), but not anything that can
actually grab the text for me.

Any help would be greatly appreciated. Thanks.

Something like this perhaps?

Dim strFound As String

With ActiveDocument.Range.Find
.Text = "\{\{*\}\}"
.MatchWildcards = True
.Execute
If .Found Then
strFound = .Parent.Text
End If
End With

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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