|
本帖最后由 weiyingde 于 2020-2-19 20:34 编辑
Public Sub 标志前后同相同色(ptern As String)
On Error Resume Next
Dim colr As Integer
Set dic1 = CreateObject("scripting.dictionary")
Set dic2 = CreateObject("scripting.dictionary")
Set RegEx = CreateObject("VBscript.RegExp")
RegEx.Pattern = ptern
RegEx.Global = True
RegEx.MultiLine = True
With ActiveDocument
sr = .Content.Text
Set mh = RegEx.Execute(sr)
For Each mt In mh
If dic1.Exists(mt.submatches(0)) = False Then
N = N + 1
Nubr1 = IIf(N > 8, N Mod 8, N)
dic1.Add mt.submatches(0), N * 2 + 1
End If
If dic2.Exists(mt.submatches(2)) = False Then
M = M + 1
Nubr2 = IIf(M > 8, M Mod 8, M)
dic2.Add mt.submatches(2), M * 2
End If
Next
ky1 = dic1.keys: tm1 = dic1.items
KY2 = dic2.keys: tm2 = dic2.items
For Each mt In mh
fst = mt.firstindex
lgh0 = Len(mt.submatches(0))
lgh1 = Len(mt.submatches(1))
lgh2 = Len(mt.submatches(2))
For x1 = 0 To UBound(ky1)
If mt.submatches(0) = ky1(x1) Then
With .Range(.Range.Start + fst, .Range.Start + fst + lgh0)
.Font.ColorIndex = tm1(x1)
.Font.Name = "Arial Black"
.HighlightColorIndex = tm1(x1 + 1)
End With
End If
Next
For x2 = 0 To UBound(KY2)
If mt.submatches(2) = KY2(x2) Then
With .Range(.Range.Start + fst + lgh0 + lgh1, .Range.Start + fst + lgh0 + lgh1 + lgh2)
.Font.ColorIndex = tm2(x2)
.Font.Name = "Arial Narrow"
.HighlightColorIndex = tm2(x2 + 2)
End With
End If
Next
Next
End With
End Sub
Sub 试试()
标志前后同项同色 "([A-Za-z]+)(\s\\upcite\{)([A-Z1-9]+)"
End Sub
|
评分
-
2
查看全部评分
-
|