Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Long Documents / November 2003

Tip: Looking for answers? Try searching our database.

Multiple search/replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 07 Nov 2003 02:28 GMT
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
Greg Maxey - 07 Nov 2003 02:46 GMT
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.

Signature

Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
Remove the obvious (wham...m)  to reply in e-mail

> I need to format a large document, and the process will
> involve a search-and-replace for about twenty items.
[quoted text clipped - 6 lines]
>
> Peter
Greg Maxey - 07 Nov 2003 02:48 GMT
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.

Signature

Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
Remove the obvious (wham...m)  to reply in e-mail

> Peter,
>
[quoted text clipped - 54 lines]
>>
>> Peter
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.