|
- Sub 去乱码编序号()
- Dim myPG As Paragraph
- Dim oType%, No%, count%, i%, rStart&, rEnd&, RegEx$, rng$
- Dim oRegEx As Object, myMatches As Object
- Set oRegEx = CreateObject("VBSCRIPT.REGEXP")
- With oRegEx
- .IgnoreCase = False
- .MultiLine = False
- .Global = True
- End With
- RegEx = "[\uF022-\uF084]+|[^" & ChrW(13312) & "-﨩,、;。“”]+"
- oType = 0: No = 0
- For Each myPG In ActiveDocument.Paragraphs
- With myPG.Range
- rng = Left(.Text, Len(.Text) - 1)
- If Trim(Len(rng)) <> 0 Then
- If Trim(rng) = "【原文】" Then
- oType = 1: No = 0
- ElseIf Trim(rng) = "【校注】" Then
- oType = 2: No = 0
- ElseIf Trim(rng) Like "【*】" Then
- oType = 0: No = 0
- ElseIf oType = 1 Then
- If rng Like "*[一-﨩]*" Then
- With oRegEx
- .Pattern = RegEx
- Set myMatches = .Execute(rng)
- End With
- count = myMatches.count
- If count > 0 Then
- No = No + count
- For i = count - 1 To 0 Step -1
- rStart = .Start + myMatches(i).FirstIndex
- rEnd = rStart + myMatches(i).Length
- With ActiveDocument.Range(rStart, rEnd)
- .Text = Chr(33 + (No - count + i + 1))
- .Font.ColorIndex = wdRed
- .Font.Bold = False
- .Font.Name = "Numbers & Pinyin"
- End With
- Next i
- End If
- End If
- ElseIf oType = 2 Then
- If Len(rng) >= 3 And rng Like "*[" & ChrW(13312) & "-﨩]*" Then
- For i = 1 To 3
- If .Characters(1) Like "[" & ChrW(13312) & "-" & ChrW(-4063) & ChrW(-3963) & "-﨩]" Then Exit For
- .Characters(1).Delete
- Next i
- No = No + 1
- .InsertBefore Chr(33 + No) & "、"
- With .Characters(1).Font
- .ColorIndex = wdRed
- .Bold = False
- .Name = "Numbers & Pinyin"
- End With
- End If
- End If
- End If
- End With
- Next myPG
- Set myPG = Nothing
- Set oRegEx = Nothing
- Set myMatches = Nothing
- End Sub
复制代码 |
|