|
本帖最后由 duquancai 于 2019-7-26 21:42 编辑
没时间考虑算法,也就不管效率了!!!- Sub main()
- Dim doc As Document, d As Object
- Set doc = ActiveDocument
- Call yuchuli(doc)
- Set d = CreateObject("Scripting.Dictionary")
- Call get_num(doc, d)
- Call mark_num(doc, d)
- End Sub
- Sub yuchuli(ByRef doc As Document)
- doc.Content.Find.Execute "、[!^13]@^13", , , -1, , , , , , "、^p", 2
- doc.Content.Find.Execute "^13{2,}", , , -1, , , , , , "^p", 2
- End Sub
- Sub get_num(ByVal doc As Document, ByRef d As Object)
- Dim p As Paragraph
- For Each p In doc.Paragraphs
- d(p.Range.Text) = d(p.Range.Text) + 1
- Next
- End Sub
- Sub mark_num(ByRef doc As Document, ByVal d As Object)
- Dim key, p As Range
- key = d.keys()
- Set p = doc.Content
- For i = 0 To UBound(key)
- If d(key(i)) > 1 Then
- With p.Find
- If .Execute(key(i)) Then
- With .Parent
- .End = .End - 1: .InsertAfter "(重复" & d(key(i)) & "个)"
- .Start = .End + 1
- End With
- End If
- End With
- End If
- Next
- End Sub
复制代码 |
|