Written by Allen Wyatt (last updated June 30, 2022)
This tip applies to Word 97, 2000, 2002, and 2003
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.
Note:
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.
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!
Word 2007 uses a different file format than was used in previous versions of Word. This can cause some problems in ...
Discover MoreWant to get rid of any properties you've created for a document? You can do so by using the short macro described in this ...
Discover MoreWant the full path name for a document visible on the screen? Easily add it to a menu bar.
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-02-06 09:06:44
if you want to replace images and metadata in addition to text for instance, you can use a good commercially available software such as: https://www.officefindreplace.com
2021-02-10 00:24:16
Hi
This does not work i word/office 365.
I am not a programmer, so please fix this code for office 365.
The error is: With Application.FileSearch
Does not exist
Please send all the code...
2021-02-04 10:58:58
Art Levine
I'm using a MacBook Air running macOS Catalina version 10.15.7. Does DragandDrop work with this operating system? If not, can anyone recommend a product that does for multiple document editing on this platform?
2020-11-15 23:49:15
Giant Joe
Doesn't work. I'm not sure if the problem is related to header text, but I gave up trying to make it work. Waste of time.
2020-03-28 08:57:02
Allen
I believe it does, Randy, but you'll need to check with the good folks at The Editorium. (They created MegaReplacer.)
-Allen
2020-03-28 07:42:40
Randy
Hi there!
Do you know if MegaReplacer works on modern versions of Word, e.g,. 2020?
2020-02-28 20:16:21
Patrick Shea
How would I Search and Replace to include the case. For example, I want to search for the word MYTEXT and replace it with Mytext?
2019-02-05 04:28:10
Jigneshkumar K Pandya
function Application.FileSearch is not working if anyone have alternate codes please let me know
2019-01-03 13:41:28
If you want a bit more functionality, if you want to replace images and metadata in addition to text for instance, you can use a good commercially available software such as: https://www.officefindreplace.com
2018-12-17 07:03:40
Asad Rauf
Is there a way to change the hyperlink using the same code. I have text that links to a google form. I want to update the link in all files.
2018-09-20 14:48:29
juan carlos
Hi there,
I'm wondering how can I password protect just for editing all word files in a folder?
I start running the document control activities and found that 500 files to be protected is a huge task to be performed one by one.
Thanks for your time on this request
Kind Regards
Carlos
2018-07-12 08:51:16
Richard Peers
The function Application.FileSearch was removed after Office 2007, so the code on this page sadly no longer works.
2018-06-12 15:00:35
Rachel
Hi, Is it possible to change the Title property in several (hundreds) of Word documents? Unfortunately 350 documents started from one original ancestor and all of them kept the original Title property. Thanks!
2018-05-17 10:57:24
Another option is to use a software to do this. We use https://www.officefindreplace.com, works great.
2017-11-28 09:44:46
Jake
Or you could just use this program, it's much, much simpler.
http://www.gmayor.com/document_batch_processes.htm
2017-11-03 16:46:11
pamusician
This macro was exactly what I was looking for. Thanks for sharing!
2017-04-23 18:28:49
Hello,
I saw your information on editing multiple word documents at once. I have written a free program (.exe for windows and .app for mac) which allows users to edit the headers for multiple word documents at once, as long as the headers across all the documents have similar formatting. To download and learn more, go to https://suitablesoftware.wixsite.com/home
-SuitableSoftware
2017-01-20 11:46:47
RobinCB
FYI: http://www.dragondrop.com is no longer available.
2016-10-10 10:52:07
Joe
You can also use a 3rd party tool to do this sort of thing very easily. Try something like www.officefindreplace.com for a quick fix to all of your documents.
2016-09-27 22:12:11
Steve
Allen,
Thanks for the great tip, it was exactly what I was looking for!
Cheers!
-Steve
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments