|
以下为VBA小菜鸟本人之最新自编独创代码,希望对大家有所帮助:- Sub 删除段落首尾空格及空行()
- ActiveDocument.Content.Find.Execute findtext:="^l", replacewith:="^p", Replace:=wdReplaceAll '手动换行符 => 段落标记(全部替换)
- ActiveDocument.Content.Find.Execute findtext:="^13", replacewith:="^p", Replace:=wdReplaceAll '真假回车符 => 段落标记
- ActiveDocument.Content.Find.Execute findtext:="^s", replacewith:=" ", Replace:=wdReplaceAll '不间断空格 => 半角空格
- ActiveDocument.Content.Find.Execute findtext:="(", replacewith:="(", Replace:=wdReplaceAll '英文左括号 => 中文左括号
- ActiveDocument.Content.Find.Execute findtext:=")", replacewith:=")", Replace:=wdReplaceAll '英文右括号 => 中文右括号
- Dim i As Paragraph, n As Long
- For Each i In ActiveDocument.Paragraphs
- For n = 1 To i.Range.Characters.Count
- If i.Range Like " *" Or i.Range Like " *" Or i.Range Like Chr(9) & "*" Then
- i.Range.Characters(1).Delete
- ElseIf i.Range Like "* " & Chr(13) Or i.Range Like "* " & Chr(13) Or i.Range Like "*" & Chr(9) & Chr(13) Then
- Do
- i.Range.Select
- Selection.EndKey Unit:=wdLine
- Selection.TypeBackspace
- Loop Until Asc(i.Range.Characters(i.Range.Characters.Count - 1)) <> 32 Or Asc(i.Range.Characters(i.Range.Characters.Count - 1)) <> 9
- Else
- Exit For
- End If
- Next n
- If Len(i.Range) = 1 Then i.Range.Delete
- Next
- ' 特例
- For Each i In ActiveDocument.Paragraphs
- If i.Range Like " “*" Or i.Range Like " (*" Then
- i.Range.Select
- Selection.HomeKey Unit:=wdLine
- Selection.Delete Unit:=wdCharacter, Count:=1
- End If
- If i.Range Like "*) " & Chr(13) Or i.Range Like "*” " & Chr(13) Then
- i.Range.Select
- Selection.EndKey Unit:=wdLine
- Selection.TypeBackspace
- End If
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|