当你日复一日地使用 Word 时, 你往往会积累大量的文档. 如果这些文档用于标准目的, 则文档包含一些相同的信息并不罕见.
例如, 您可能拥有包含您提交给不同报纸和杂志的故事的文档. 虽然各个故事可能不同, 但每个文档可能包含您的姓名和联系信息. 如果您的联系信息发生变化, 或者您决定对您的姓名使用不同的拼写, 您可能会想方设法对所有文档进行一次性更改.
不幸的是, Word 不包括这种类型的功能. 您可以选择依赖第三方解决方案, 也可以编写自己的宏来进行更改. 有许多第三方程序提供了处理多个文档时所需的搜索和替换功能. 以下是 WordTips 订阅者建议的一些内容:
- MegaReplacer( http://www.editorium.com/14843.htm )
- WordFisher( http://www.wordfisher.com/wf4.htm )
单词搜索和替换 ( http://www.funduc.com/search_replace.htm )
InfoRapid Search&Replace( http://www.inforapid.com/html/searchreplace.htm )
高级查找和替换 ( http://www.abacre.com/afr/ )
Word 开发人员 Malcom Smith 还创建了一个宏, 它将执行搜索并替换目录. 如果你想看到它, 你可以访问 http://www.dragondrop.com/ . 只需单击页面右侧的 "查找和替换 Word" 链接即可.
你也可以使用以下的 vba 宏代码, 可以替换特定目录下所有 Word 文档的特定文本
- 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
来源: http://www.mzh.ren/changing_information_in_multiple_documents.html