|
- Option Explicit
- Sub bluetext()
- Dim i As Paragraph, mt, oRang As Range, n%, m%, iOffset As Long, sTxt As String
- ActiveDocument.Range.Font.Fill.ForeColor.RGB = 0
- With CreateObject("vbscript.regexp")
- .Pattern = "\x0b([^\x0b\r]*)\r"
- .Global = True
- For Each i In ActiveDocument.Paragraphs
- sTxt = i.Range.Text
- If Len(sTxt) > 2 Then
- iOffset = 0
- If i.Range.Information(wdWithInTable) Then
- If i.Range.Start = i.Range.Cells(1).Range.Start Then
- iOffset = 1
- End If
- End If
- For Each mt In .Execute(sTxt)
- m = mt.FirstIndex
- n = mt.Length
- Set oRang = ActiveDocument.Range(i.Range.Start + m + iOffset, i.Range.Start + m + n)
- ' oRang.Select
- oRang.Font.ColorIndex = wdBlue
- Next
- End If
- Next
- End With
- End Sub
- ' 起始位置存在一个零宽度不可见字符
- Sub Demo()
- Dim i
- For i = 0 To 4
- With ActiveDocument.Range(i, i + 1)
- Debug.Print "第" & i & "个字符:[" & .Text & "]", Len(.Text)
- End With
- Next
- End Sub
复制代码 |
|