Loading
Word.Tips.Net WordTips (Menu Interface)

Changing Information in Multiple Documents

As you use Word, day in and day out, you tend to accumulate lots and lots of documents. If these documents are used for a standard purpose, it is not unusual for the documents to contain some of the same information.

For instance, you may have documents that contain stories that you submit to different newspapers and magazines. While the individual stories may be different, each document may contain your name and contact information. If your contact information changes, or if you decide to use a different spelling for your name, you may long for a way to do a universal change to all the documents at once.

Unfortunately, Word does not include this type of capability. Your options are either to rely on a third-party solution or write your own macro to do the changes. There are a number of third-party programs that offer the type of search-and-replace function necessary when working with multiple documents. The following are just a few of the ones suggested by WordTips subscribers:

Word developer Malcom Smith has also created a macro that will perform search and replaces across directories. If you want to see it, you can visit http://www.dragondrop.com. Just click the Find and Replace for Word link, at the right side of the page.

If you don't mind using your own macros, the following shows the techniques inherent in stepping through the documents in a particular folder.

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
            ' 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 address
                selection.Find.ClearFormatting
                selection.Find.Replacement.ClearFormatting
                With selection.Find
                    .Text = "OldAddress"
                    .MatchCase = True
                    .Replacement.Text = "NewAddress"
                End With
                selection.Find.Execute Replace:=wdReplaceAll

                ' replace e-mail address
                With selection.Find
                    .Text = "Oldemail"
                    .Replacement.Text = "Newemail"
                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 street address, but also your e-mail 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 information is. Change the .Lookin parameter early in the macro to indicate where the macro should search; make sure you use a full path. Then, within the main body of the macro, update the .Text and .Replacement.Text parameters to reflect what you are searching for and replacing with.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3783) applies to Microsoft Word 97, 2000, 2002, and 2003.

Related Tips:

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you them! Check out Microsoft Word 2013 Step by Step today!

 

Comments for this tip:

Sukhvinder    12 Sep 2014, 09:47
Thanks a lot!!!!
Very helpful
Jignesh Pandya    23 Apr 2014, 10:49
I want to extract name of my pdf files from particular folder number of files are very high
Jon    22 Apr 2014, 07:38
Thanks for the kind offer William but the job is done now.
William    12 Apr 2014, 10:57
Hey, I wrote a simple terminal app in java to change the header on multiple word docs at once. Shoot me an email if you are interested
William    12 Apr 2014, 10:55
Hey,
I wrote my friend a command line java utility to change the header on multiple word documents in a folder. Its bare bones, but gets the job done. Shoot me an email if you are interested and i can email it precompiled
Jon    13 Feb 2013, 05:46
Hi Emily,
I did find various codes to do this but none seemed perfect for what I needed to do which was change an address in the headers of loads of document templates. As the existing addresses could vary slightly, the find/replace didn't work and when it did, the format was sometimes wrong.

I don't know if this works for what you want to do but this is how I did it: I opened a new document and made the header exactly as I wanted it to be. Then opened a document that needed to be changed (make sure that these are the only two Word docs open). Then I went back to the new doc and recorded a macro in it that copies the new header, opens the second document, deletes the entire header and copies in the new header and alters the format (just in case). When it has finished, do a save-as. So when I come across a template that needs changing, I open the doc with the macro in it, run the macro and the job's done. Hope that helps
Emily    13 Feb 2013, 00:33
I same issue John, let me know if you find a solution!
Jon    27 Sep 2012, 05:09
This code is great and works perfectly for replacing text in the body of my Word documents. The trouble is that the text I want to replace is in the document header and this code does not look there. Do you have the code to find/replace in the header please?

Thanks

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 3+4? (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.