|
- Sub 中英换行()
- Dim myPG As Paragraph
- Dim oRegEx As Object, myMatches As Object
- Dim j%, i%, rStart&, rEnd&
- Set oRegEx = CreateObject("VBSCRIPT.REGEXP")
- With oRegEx
- .Global = True
- .IgnoreCase = False
- .MultiLine = False
- .Pattern = "[a-zA-Z][\u0020-\u007f’]{5,}[,!?。]*" ' "5"代表5个英文字符以内的保留在汉字中,比如文中的OK,Um
- End With
- For j = ActiveDocument.Paragraphs.Count To 1 Step -1
- Set myPG = ActiveDocument.Paragraphs(j)
- With myPG.Range
- If Len(.Text) > 1 Then
- Set myMatches = oRegEx.Execute(.Text)
- If myMatches.Count > 0 Then
- For i = myMatches.Count - 1 To 0 Step -1
- rStart = .Start + myMatches(i).FirstIndex
- rEnd = rStart + myMatches(i).Length
- If ActiveDocument.Range(rEnd, rEnd + 1) <> Chr(13) Then _
- ActiveDocument.Range(rEnd, rEnd).InsertAfter Chr(13) & Chr(13)
- If ActiveDocument.Range(rStart - 1, rStart) <> Chr(13) Then _
- ActiveDocument.Range(rStart, rStart).InsertBefore Chr(13)
- Next i
- End If
- End If
- End With
- Next j
- Set myPG = Nothing
- Set oRegEx = Nothing
- Set myMatches = Nothing
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|