replace all

A

Ashish Sharma

With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = True
.Execute FindText:="Inc aa", _
ReplaceWith:="incorporated", Replace:=wdReplaceAll
End With

if my document contains below line of code
inc aa for the inc aabcde [/QUOTE]and incart the inc aa

the above code will replace inc aabcde also

is this a bug in ms word
 
J

John McGhie

No bug. The FindText:="Inc aa" is a partial string match.

Set the "Whole words only" option to True if you want an exact string match.

http://msdn.microsoft.com/en-us/library/aa213880(office.11).aspx

It's much safer to record these things with the Macro Recorder and paste the
result into your code. Saves looking up all these weird properties :)

Cheers


With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = True
.Execute FindText:="Inc aa", _
ReplaceWith:="incorporated", Replace:=wdReplaceAll
End With

if my document contains below line of code
inc aa for the inc aabcde
and incart the inc aa

the above code will replace inc aabcde also

is this a bug in ms word[/QUOTE]

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 

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