Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Mass Search and Replace.

Mass Search and Replace

Written by Allen Wyatt (last updated September 28, 2024)
This tip applies to Word 97, 2000, 2002, and 2003


Over time it is very possible to collect a huge number of documents. At some point you may want to make the same change to each of the documents in the collection. For instance, you may need to change the company name within each document. Obviously you can open each document, make the change, and then save the document, but that process can quickly become tiring if you have hundreds or thousands of documents to process.

What to do? Consistent with the point that has been made in other issues of WordTips, anytime you have something that is mundane and tiresome to accomplish, you can often use a macro to handle the work for you. For instance, you could write a macro that would step through all the documents in a directory, load each in turn, search for and change the necessary text, and resave the document. This process is no different than the process you would follow manually, except that it is done under the control of the macro. This makes it much easier and faster.

The following is an example of a macro that could do the trick:

Public Sub MassReplace()
    With Application.FileSearch
        .LookIn = "C:\"             ' where to search
        .SearchSubFolders = True    ' search the subfolders
        .FileName = "*.doc"         ' file pattern to match

        ' if more than one match, execute the following code
        If .Execute() > 0 Then
            ' to display how many files this macro will access,
            ' uncomment the next line of code
'            MsgBox "Found " & .FoundFiles.Count & " file(s)."

            ' for each file you find, run this loop
            For i = 1 To .FoundFiles.Count
                ' open the file based on its index position
                Documents.Open FileName:=.FoundFiles(i)

                ' search and replace the company name
                selection.Find.ClearFormatting
                selection.Find.Replacement.ClearFormatting
                With selection.Find
                    .Text = "OldCompanyName"
                    .MatchCase = True
                    .Replacement.Text = "NewCompanyName"
                End With
                selection.Find.Execute Replace:=wdReplaceAll

                ' replace street address
                With selection.Find
                    .Text = "OldStreetAddress"
                    .Replacement.Text = "NewStreetAddress"
                End With
                selection.Find.Execute Replace:=wdReplaceAll

                ' replace the City, State, and Zip code
                With selection.Find
                    .Text = "OldCityStateAndZip"
                    .Replacement.Text = "NewCityStateAndZip"
                End With
                selection.Find.Execute Replace:=wdReplaceAll

                ' save and close the current document
                ActiveDocument.Close wdSaveChanges
            Next i
        Else
            ' if the system cannot find any files
            ' with the .doc extension
            MsgBox "No files found."
        End If
    End With
End Sub

This macro is quite powerful, and it allows you to not just change a company name, but also your company's address. All you need to do is make changes to specify which directory and drive to use in your search, as well as what the old and new company information is.

If dealing with macros is a little beyond what you want to tackle, there are also a number of different commercial products available that will work with Word documents. Various subscribers have suggested the following programs:

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1462) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Mass Search and Replace.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting a View

When you no longer need a view, you can get rid of it by deleting it. Deleting unnecessary views is a good idea because ...

Discover More

Copying Fill Color in a Table

You may spend some time getting the color in a portion of a table just right, only to be faced with the task of copying ...

Discover More

Centering a Paragraph with the Keyboard

Need a quick shortcut that you can use to center your paragraph between the margins? The answer is here.

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Weird Characters in File Names

If you ever end up with file names that contain percent signs followed by numbers, it could be due to some sort of file ...

Discover More

Combining Documents

Need to combine quite a few text documents? A macro may be the easiest way to stuff them all into a single Word document.

Discover More

Periodically Delete TMP Files

After using Word for a while, you may notice some "litter" of unused files on your hard drive. This tip explains how ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six minus 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.