Find/Replace Multiple Words

S

singeredel

How can this find/replace be modified to enable search and replace of
multiple words without repeating this code for each word to be replaced (if
more efficient)?

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "{DOI}"
.Replacement.Text = DOI$
.Forward = True
.Wrap = wdFindContinue
.MatchCase = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Thank you!
 
J

Jezebel

Dim pFind as string
Dim pReplace as string
Dim pIndex as long

For pIndex = 1 to whatever
pFind = Choose(pIndex, "Word 1", "Word 2", ....)
pReplace = Choose(pIndex, "New word 1", "New word 2", ....)

With Selection.Find
.Text = pFind
.Replacement.Text = pReplace

:
End with
Next
 
K

Klaus Linke

Or define a macro that takes two string arguments for the search text and replacement text, and call that?

Klaus
 

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