macro to remove carriage returns

  • 1
  • Question
  • Updated 4 years ago
Getting rid of hard line breaks in pasted text.

I cut and paste a lot from pdfs and inevitably it leaves a lot of line breaks lying around. When this occurs in Word I wrote a little macro to replace them out. Here it is below. How do I amend this so that when I come across a Note, Topic/Sub-Topic I can selectively remove them with a minjet macro.

Sub pagebreaks()
'
' pagebreaks Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "|"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "|"
        .Replacement.Text = "^p^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

End Sub
Photo of hal9000

hal9000

  • 1 Post
  • 0 Reply Likes

Posted 4 years ago

  • 1

Be the first to post a reply!