Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Mass Search and Replace.

Mass Search and Replace

Written by Allen Wyatt (last updated September 12, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


2

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 Word macro that could do the trick:

Public Sub MassReplace()
    Dim Directory As String
    Dim FType As String
    Dim FName As String

    Directory = "d:\temp"
    FType = "*.docx"

    ChDir Directory
    FName = Dir(FType)
    ' for each file you find, run this loop
    Do While FName <> ""
        ' open the file
        Documents.Open FileName:=FName

        ' 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

        ' look for next matching file
        FName = Dir
    Loop
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 (8477) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word 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

Breaking Links in Lots of Documents

Breaking document links can be a tedious chore, especially if there are lots of links and lots of documents. This tip ...

Discover More

Inserting the Document Creation Date

One of the pieces of information tracked by Word is when a document was first created. Here's how you can access that ...

Discover More

Getting Rid of a Text Box, but Not the Text

Text boxes are designed to hold text. (Makes sense, right?) If you want to get rid of a text box, yet still keep the ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Changing the Document Inspector's Comment Name

The Document Inspector can be a great tool when you want to prepare your document to be shared with others and you want ...

Discover More

Setting a Default for the Object Browser

Does it bother you that when you press Ctrl+Page Up or Ctrl+Page Down you aren't always taken to the top of the previous ...

Discover More

Tools to Boost Motivation and Productivity

Sometimes a writer needs motivation to keep ploughing ahead in their craft. Word doesn't really include any tools to help ...

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 two more than 7?

2021-01-25 13:09:11

larry Schwartz

Is there a way to ensure that a "master" index entry is not separated from its subordinates by a column or page break?


2021-01-24 19:48:10

Tyler

Allen, this has worked perfectly for me! I will soon be using it to change over organisational roles (old to new) however I have encountered a problem that not all areas of the document are searched.

How can this be expanded to include header/footer and text boxes?

Range instead of Selection?


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu 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.