Multiple search/replace

P

Peter

I need to format a large document, and the process will
involve a search-and-replace for about twenty items.
Rather than repeat the process individually, is there any
way to create a list and have Word automatically search
for all of the objects in, say, column A and replace them
with objects in column B?

Thanks,

Peter
 
G

Greg Maxey

Peter,

Here is a macro to do that:

Sub MultiFindAndReplace()
'
' MultiFindAndReplace Macro
' Macro created 1/7/2003 by Gregory K. Maxey
'
Dim WordList As Document
Dim Source As Document
Dim i As Integer
Dim Find As Range
Dim Replace As Range
Set Source = ActiveDocument
' Change the path and filename in the following to suit where you have your
list of words
Set WordList = Documents.Open(FileName:="D:\My Documents\Word Documents\Find
and Replace List.doc")
Source.Activate
For i = 2 To WordList.Tables(1).Rows.Count
Set Find = WordList.Tables(1).Cell(i, 1).Range
Find.End = Find.End - 1
Set Replace = WordList.Tables(1).Cell(i, 2).Range
Replace.End = Replace.End - 1
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Find
.Replacement.Text = Replace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i

End Sub

You will have to create the Word list in a two column table and save it.
You will need to identify your WordList in the macro code.
 
G

Greg Maxey

I normally try to give credit where credit is due. I didn't acually create
the macro I posted a minute ago. I think it was a fellow named Larry that
provided it to me or maybe Doug Robbins. I don't remember.
 

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