|
本帖最后由 kqbt 于 2015-11-7 22:43 编辑
看了 413191246se 的方法有所启发,换了一种思路,但是代码有点长,供测试:
- '======注意======2版
- '1 跨段落匹配视为成对
- '2 多层嵌套匹配不视为成对
- '3 未测试表格中的标点
- '================
- Sub 标注不成对标点符号()
- Dim Arr(), i As Integer, m As Integer, n As Integer, o As Integer
- Dim wRng As Range, rRng As Range, sRng As Range, tRng As Range
- ActiveDocument.Content.HighlightColorIndex = wdAuto
- Arr = Array(-24146, -24145, -24144, -24143, -24138, -24137, -24136, _
- -24135, -24134, -24133, -24132, -24131, -24130, -24129, _
- -23640, -23639, 40, 41, 60, 62, 91, 93, 123, 125)
- Application.ScreenUpdating = False
- For i = 0 To UBound(Arr)
- Selection.HomeKey wdStory
- Set wRng = Selection.Range
- m = 1: n = 0: o = i Mod 2
- If o = 1 Then
- m = m - 1: n = n - 1
- Set rRng = wRng.Duplicate: GoTo line2
- End If
- line1:
- wRng.MoveUntil Chr(Arr(i))
- Set rRng = ActiveDocument.Range(wRng.End, wRng.End + 1).Duplicate
- If rRng = Chr(Arr(i)) Then
- line2:
- wRng.MoveUntil Chr(Arr(i + m))
- Set sRng = ActiveDocument.Range(wRng.End, wRng.End + 1).Duplicate
- If sRng = Chr(Arr(i + m)) Then
- Set tRng = ActiveDocument.Range(rRng.End, sRng.Start)
- 'tRng.Select
- If InStr(tRng, Chr(Arr(i + n))) Then
- If o = 0 Then
- rRng.HighlightColorIndex = wdBrightGreen
- wRng.SetRange rRng.Start, rRng.End
- GoTo line1
- Else
- wRng.SetRange sRng.Start, sRng.End
- rRng.SetRange wRng.Start, wRng.End
- GoTo line2
- End If
- Else
- If o = 0 Then
- GoTo line1
- Else
- sRng.HighlightColorIndex = wdBrightGreen
- wRng.SetRange sRng.Start, sRng.End
- GoTo line2
- End If
- End If
- Else
- If o = 0 Then
- rRng.HighlightColorIndex = wdBrightGreen
- wRng.SetRange rRng.Start, rRng.End
- GoTo line1
- End If
- End If
- End If
- Next
- Set wRng = ActiveDocument.Content
- With wRng.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- Do While .Execute("^13[0-9一二三四五六七八九十百]@[/))]", , , True, , , True)
- wRng.HighlightColorIndex = wdAuto
- wRng.SetRange wRng.End, ActiveDocument.Content.End
- Loop
- End With
- Application.ScreenUpdating = True
- MsgBox "标注完成!"
- End Sub
复制代码 |
|