Match Whole Word

J

Joanne

In a macro, I used Ctrl+Find to locate the word "East" in an addr line
and change it to "E". While this works fine, it also changes
"Eastwood" to "Ewood". I tried using MatchWholeWord=True but it didn't
help.
I notice that when I use Ctrl+Find outside of the macro environment,
it allows me to choose "Find Whole Words Only'.
My question is how do I make the macro using Ctrl+Find to use the
"Find Whole Words Only" command.
Thanks muchly for your time and expertise
Joanne
 
E

Ed

The whole Selection.Find code as recorded my the Macro Recorder usually
looks something like this:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "your text here"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

You can set these to the desired parameters. For more on this, see Execute
Method (Find Object) in the VBA help.

Ed
 
P

Peter Hewett

Hi Joanne

In the With block that's doing the Find set ".MatchWholeWord = True".
So your macro will look something like:

Public Sub EastToE
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "East"
.Replacement.Text = "E"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

HTH + Cheers - Peter
 

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