Replacing paragraph marks at the end of lines

Emails, text copied from the web, or documents prepared by those that use Word as a typewriter often have paragraph marks (technically, pilcrows, ¶) at the end of each line, with two between "paragraphs":

text with paragraph marks after every line

This can be very irritating when you're trying to make text flow, the way a Word document should

text with extra paragraph marks removed

You can remove these manually (click the Show/Hide button, Word Show/Hide button image on the Standard toolbar to see the paragraph marks if they're not visible):

  1. Choose Edit/Replace...
  2. In the Replace dialog's Find what textbox, Choose Paragraph Mark twice from the Special popup (click the blue arrow if you don't see the popup):
    Expanded Replace dialog
    OR manually enter the code for a paragraph mark, "^p", twice (e.g., ^p^p)).
  3. Enter a text string that won't be found in your document (such as qwertyioup) in the Replace with textbox.
  4. Click Replace All. Your "paragraphs" will combine, with your text string between them. This is OK.
  5. Enter a single paragraph mark (e.g., ^p) in the Replace dialog's Find what textbox. Clear the Replace with textbox.
  6. Click Replace All. This removes the remaining paragraph marks.
  7. Enter your text string in the Find what textbox. Enter a single paragraph mark in the Replace with textbox.
  8. Click Replace All. This inserts paragraph marks between the paragraphs. Close the Replace dialog.

You can automate this very easily. Here's one way:

    Public Sub ReplaceParagraphMarks()
        'J.E. McGimpsey
        Const sREPLACE As String = "!_REPLACE_RETURN_TEXT_!"
        Application.ScreenUpdating = False
        With ActiveDocument.StoryRanges(wdMainTextStory).Find
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            .Text = "^p^p"
            With .Replacement
                .Text = sREPLACE
            End With
            .Execute Replace:=wdReplaceAll
            .Text = vbNewLine
            .Replacement.Text = " "
            .Execute Replace:=wdReplaceAll
            .Text = sREPLACE
            .Replacement.Text = "^p"
            .Execute Replace:=wdReplaceAll
        End With
        Application.ScreenUpdating = True
    End Sub

Valid XHTML 1.1 Valid CSS Made on a Macintosh