|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 duquancai 于 2019-7-27 15:52 编辑
你的需求 不断的改变!下次想清楚了,一次性吐完吧!按照你这次的需求写的,请测试!- Sub main()
- Dim doc As Document, d As Object
- Set doc = ActiveDocument
- Set d = CreateObject("Scripting.Dictionary")
- Call get_num(doc, d)
- Call mark_num(doc, d)
- End Sub
- Sub get_num(ByVal doc As Document, ByRef d As Object)
- Dim re As Object, mh As Object
- Set re = CreateObject("VBScript.Regexp")
- re.Global = True: re.MultiLine = True
- re.Pattern = "^[^、]+、$"
- For Each mh In re.Execute(doc.Content.Text)
- d(mh.Value) = d(mh.Value) + 1
- Next
- End Sub
- Sub mark_num(ByRef doc As Document, ByVal d As Object)
- Dim key, re As Object, mhs As Object, n&, i&, j&, flag As Boolean, t&
- key = d.keys()
- Set re = CreateObject("VBScript.Regexp")
- re.Global = True: re.MultiLine = True
- For i = 0 To UBound(key)
- If d(key(i)) > 1 Then
- re.Pattern = "^" & key(i): flag = False: t = 0
- Set mhs = re.Execute(doc.Content.Text)
- For j = 0 To mhs.Count - 1
- n = mhs(j).FirstIndex
- If Not flag Then
- With doc.Range(n, n + Len(key(i)))
- If .MoveEndWhile("(") = 1 Then Exit For
- .InsertAfter "(重复" & d(key(i)) - 1 & "个)"
- t = Len("(重复" & d(key(i)) - 1 & "个)")
- End With
- flag = True
- Else
- doc.Range(n + t, t + n + Len(key(i))).Font.ColorIndex = 6
- End If
- Next
- End If
- Next
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|