Getting rid of empty spaces between empty paragraph marks is tricky.
Helmut's code does this, but will also delete empty spaces between the
end of the last sentence in each paragraph and the paragraph mark, which
may not be desired. Also, his first search in the PurgeLines macro
should be for .Text = " {1,}^013", not for .Text = " {2,}^013" .
Here is my own macro that I use for this purpose. If you want the macro
to operate on the whole document rather than on the selection or from
the IP downward, simply changes all instances of .Wrap = wdFindStop to
..Wrap = wdFindContinue
Sub TwoParaMarksToOneParaMark()
' Changes instances of two or more consecutive paragraph marks to one.
' Eliminates any spaces between paragraph marks.
' Operates on selection or from IP to end of document.
' If there are empty paragraph marks at end of doc, leaves two empty
paragraph marks.
' Note that replacement text must be ^p not ^13, since ^13 is not a real
para mark.
Application.ScreenUpdating = False
' Get rid of any spaces between paragraph marks
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(^13)( {1,})(^13)"
.Replacement.Text = "\1\3"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Run above code again because I can't otherwise get the second para
mark in the
' first running of the code to be the first para mark in the second
running
With Selection.Find
.Text = "(^13)( {1,})(^13)"
.Replacement.Text = "\1\3"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Delete extra paragraph marks.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13{2,}"
.Replacement.Text = "^p"
.MatchWildcards = True
.Forward = True
.Wrap = wdFindStop
End With
Selection.Find.Execute Replace:=wdReplaceAll
' clear Find box
With Selection.Find
..Text = ""
..Replacement.Text = ""
..MatchWildcards = False
End With
End Sub
Also, if you're interested, here is a macro that deletes empty paragraph
marks at end of doc, leaving just the end of document paragraph mark.
Sub EmptyParasAtEndDelete()
' Deletes empty paragraph marks, linebreaks, spaces, tabs and squares
' at end of document then returns cursor to starting point.
Dim r1 As Range, r2 As Range
Set r1 = Selection.Range
Selection.EndKey wdStory
' Extend selection over final para mark
Selection.EndKey wdStory, wdExtend
Set r2 = Selection.Range
r2.MoveStartWhile cset:=vbCr & vbTab & " " & Chr(11) & Chr(26), _
Count:=wdBackward
r2.Delete
r1.Select
End Sub