This is slightly improved, as it deleted any leftover comma at end of
document.
Remember, you can run this either from the beginning of document or some
point in document, or select text and run the macro on the selection.
Sub JoinAddressLinesIntoOne()
' by Larry
' Works in conjunction with DoJoinParas function below.
' Operates either from insertion point to end of doc or on selection.
' Make range of selection in order to return to it
Dim r As Range
Set r = Selection.Range
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.MatchWildcards = False
' Change all line breaks to paragraph marks
Call DoJoinParas("^l", "^p", False)
' Set aside double para breaks so as not to change them
Call DoJoinParas("^13{2,}", "*&*", True)
' Change two spaces followed by para break to two spaces
Call DoJoinParas(" ^p", ", ", False)
' Change one space followed by para break to one space
Call DoJoinParas(" ^p", ", ", False)
' Change sole para break to one space
Call DoJoinParas("^p", ", ", False)
' restore the double para breaks.
Call DoJoinParas("*&*", "^p^p", False)
' change single hyphens surrounded by space to double nonbreaking
hyphens
Call DoJoinParas(" - ", "^~-", False)
' Clear up comma at end of last affected line
Application.ScreenUpdating = False
Selection.Collapse wdCollapseEnd
Selection.MoveStartWhile cset:=", ", Count:=wdBackward
Selection.Delete
' Clear up comma at end of document
Selection.EndKey wdStory
Selection.MoveStartWhile cset:=", ", Count:=wdBackward
Selection.Delete
' return cursor to starting point or to beginning of selection, and
dismiss selection.
r.Select
Selection.Collapse wdCollapseStart
' clear Find box
With Selection.Find
..Text = ""
..Replacement.Text = ""
End With
End Sub
Sub DoJoinParas(findText As String, ReplaceText As String, _
bMatchWildCards As Boolean)
With Selection.Find
.MatchWildcards = bMatchWildCards
.Text = findText
.Replacement.Text = ReplaceText
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
' Selection.Find.Execute Replace:=wdReplaceAll
End Sub