|
本帖最后由 weiyingde 于 2020-2-20 19:41 编辑
如果两个的顺序一致,那就填没有意思的。
Sub 群体替换()Dim arr, brr, idoc As Document, xdoc As Document
With ActiveDocument.Content
.Find.Execute "^13^13", , , , , , , , , "^p", 2
arr = Split(.Text, Chr(13))
End With
Set idoc = Documents.Open(ThisDocument.Path & "\" & "替换的顺序.doc")
brr = Split(idoc.Content, Chr(13))
idoc.Close False
Set xdoc = Documents.Open(ThisDocument.Path & "\" & "被替换的文档.doc")
With xdoc
For i = 1 To .Paragraphs.Count
For j = 0 To UBound(arr) - 1
With .Paragraphs(i)
If Left(.Range.Text, Len(.Range.Text) - 1) = brr(j) Then
'.Range = arr(j) & Chr(13)
xdoc.Range(.Range.Start, .Range.Start + Len(.Range.Text) - 1) = arr(j)
End If
End With
Next
Next
End With
xdoc.Save
xdoc.Close
End Sub
如果合适,赏朵小花。
附件如下: |
|