From: ent on
Hi all


what type of code can execute a simple "search and replace all" for a
string in a document?

I need some code that I can associate to a keyboard shurtcut and tha
performs something like:

SEARCH AND REPLACE ALL "the yellow lemon" WITH "the green lime"

thanks!
From: Doug Robbins - Word MVP on
Ctrl+H

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

<ent(a)ent.ent> wrote in message news:e1j4w5vwKHA.5036(a)TK2MSFTNGP02.phx.gbl...
> Hi all
>
>
> what type of code can execute a simple "search and replace all" for a
> string in a document?
>
> I need some code that I can associate to a keyboard shurtcut and tha
> performs something like:
>
> SEARCH AND REPLACE ALL "the yellow lemon" WITH "the green lime"
>
> thanks!

From: ent on
Doug Robbins - Word MVP wrote:
> Ctrl+H
>

Yeas, but I need to do the same with some code because I have a list of
string to change and doing it manually takes a lot of time.

Any code example?

Thanks
From: Doug Robbins - Word MVP on
Dim Findstr As Variant
Dim Replacementstr As Variant
Dim i As Long
Findstr = Split("find1,find2,find3,find4", ",")
'replace find1, etc in the line above with the words that you want to be
replaced
Replacementstr = Split("replace1,replace2,replace3,replace4", ",")
'replace replace1, etc in the line above with the replacement words in the
correct order
For i = 0 To UBound(Findstr)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=Findstr(i), Forward:=True, _
MatchWildcards:=False, Replacewith:=Replacementstr(i), _
Wrap:=wdFindContinue, MatchCase:=False) = True
Loop
End With
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

<ent(a)ent.ent> wrote in message news:#IQn468wKHA.5132(a)TK2MSFTNGP05.phx.gbl...
> Doug Robbins - Word MVP wrote:
>> Ctrl+H
>>
>
> Yeas, but I need to do the same with some code because I have a list of
> string to change and doing it manually takes a lot of time.
>
> Any code example?
>
> Thanks