在word10中同时更改多个文档

在word10中同时更改多个文档

假设有几份文档需要更改地址。有没有办法更新一份文档,所有文档都会更改?或者这是否需要从头开始使用链接方法?这些文档是安装说明,以后可能需要更改零件编号,这可能会影响几份类似的文档。是否有 MS Word 插件可以实现此目的?

谢谢乔治

答案1

我能看到两种解决方案:

详情请参阅文章 如何在多个 Word 文档中查找和替换内容

为防止本文消失,下面会复制此宏。此宏会显示三个输入框,要求输入:文件夹、搜索文本和替换文本。

Sub FindAndReplaceInFolder()
  Dim objDoc As Document
  Dim strFile As String
  Dim strFolder As String
  Dim strFindText As String
  Dim strReplaceText As String

  '  Pop up input boxes for user to enter folder path, the finding and replacing texts.
  strFolder = InputBox("Enter folder path here:")
  strFile = Dir(strFolder & "\" & "*.docx", vbNormal)
  strFindText = InputBox("Enter finding text here:")
  strReplaceText = InputBox("Enter replacing text here:")

  '  Open each file in the folder to search and replace texts. Save and close the file after the action.
  While strFile <> ""
    Set objDoc = Documents.Open(FileName:=strFolder & "\" & strFile)
    With objDoc
      With Selection
        .HomeKey Unit:=wdStory
        With Selection.Find
          .text = strFindText
          .Replacement.text = strReplaceText
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
      End With
      objDoc.Save
      objDoc.Close
      strFile = Dir()
    End With
  Wend
End Sub

相关内容