|
可试试如下代码:- Sub test()
- 'AAA文档为活动文档,且BBB文档须已打开
- Dim Btext() As String
- Dim Findtext() As String
- Dim i As Integer
- Dim j As Integer
- Dim n As Integer
-
- Application.ScreenUpdating = False
- Btext = Split(Documents("BBB.docx").Range.Text, Chr(13))
- Application.Options.DefaultHighlightColorIndex = wdYellow
- With ActiveDocument.Content.Find
- .MatchWildcards = True
- .Replacement.Highlight = True
- For i = 0 To UBound(Btext)
- If InStr(Btext(i), vbTab) > 0 Then
- ReDim Preserve Findtext(1, j)
- Findtext(0, j) = Split(Btext(i), vbTab)(0)
- Findtext(1, j) = Mid(Btext(i), Len(Findtext(0, j)) + 2)
- Do While Right(Findtext(1, j), 1) = vbTab
- Findtext(1, j) = Mid(Findtext(1, j), 1, Len(Findtext(1, j)) - 1)
- Loop
- If InStr(ActiveDocument.Range.Text, Findtext(0, j)) > 0 Then
- .Execute Findtext:=Findtext(0, j), replacewith:="^&(" & Findtext(1, j) & ")", Replace:=wdReplaceAll
- n = n + 1
- End If
- j = j + 1
- End If
- Next
- End With
- Application.ScreenUpdating = True
- MsgBox "共找到" & n & "条BBB文档中的重复内容。" '并非AAA文档的重复条目
- End Sub
复制代码 |
|