|
以下代码可以删除空格和空白行
Sub 除空行()
'清除文中空格
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'删除空行
ActiveDocument.Paragraphs.First.Range.Select
For i = 1 To ActiveDocument.Paragraphs.Count
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.Paragraphs(1).Range.Select
If Selection.Words.Count < 2 Then
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Next
ActiveDocument.Paragraphs.First.Range.Select
Selection.MoveLeft Unit:=wdCharacter, Count:=1
ActiveDocument.Save
End Sub |
|