|
|
This is a Word 97 document with embedded macros which allow you to automatically search through multiple documents in multiple directories, and replace multiple words. For example, you could replace "Mega Corporation" with "MegaCorp, Inc.", and simultaneously replace "Mega" with "MegaCorp" -- and do it on hundreds of files scattered across your PC or network.
Why did I write it? Because my company went through a name change! We needed to change thousands of documents and templates. They were estimating it would take six months to complete. And they were actually doing it manually. I spent one week writing and testing the program, then gave it to a manager who let it loose on the network. After two hours of watching the screen fly, our office finished the "six month" job.
You'll have to fill out a list of your file masks and word replacements,
for example:
F:\Projects\Leases\*.doc
C:\My Documents\*.doc
Mega Corporation=MegaCorp, Inc.
Mega Corp=MegaCorp, Inc.
Mega=MegaCorp
I know, the above configuration list looks odd to be mixing file locations and text replacements, but since file masks don't have equal signs, it's easy for my code to see what is what. Text replacement is done in the order it appears in the configuration file. Please notice the logical necessity to do "big" replacements before "small" replacements.
Frankly, there are other programs written that can do this, but I couldn't get them to work. By using Word 97, I am able to open almost anything. Obviously, you'll need to have Word configured so it can open and save whatever it is you'll be modifying.
I've noticed that the "GSR.DOC" file doesn't like to be run from the network. It throws a path/file access error at startup. So put the darn thing on your local (C:) drive and run it from there!
If files are read-protected by a password, you'll have to enter the password when the macro stops and asks you for it. If you hit a file that is write-protected, the macro will skip it. Any file that the macro cannot do an open, replace, and save operation on will be logged (And the list is displayed automatically for you when the macro finishes). Likewise, a list is generated and displayed showing every change that was made.
Because the file linked in the "Download Now" is the actual Word document, you may have to right-click to convince your browser to download (versus display) the file.
The macros are not protected, so you are free to view and modify them.
Somebody asked me about changing text in headers and footers, so I added
that capability here. Someone else wanted the changed
text to be red-colored so he could find it easier. I have the red version
here. Someone else darn near re-wrote my
entire macro to open web pages and do currency conversions.
Yikes! Since I no longer use Microsoft Word at home, he was nice
enough to send me his modifications as separate BAS and RTF files.
I added our email exchange on the matter as a TXT file. Finally,
someone else was nice enough to point out an excellent discussion
of the general case of using Word macros to do text replacements
at the mvps.org web site. Read it here: http://www.mvps.org/word/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
Other Search-and-Replace Programs
http://www.inforapid.de/html/searchreplace.htm
Lost? Look at the site map.
Bad links? Questions? Send me mail.