• Manual line break macro (2002)

    Author
    Topic
    #439867

    Afternoon –

    Am trying to edit a macro, but don’t know the correct syntax. I do a lot of copy/paste from the Web and find that most of the text comes over with manual line breaks. The macro below does delete those breaks and gives me what I need. But, when there is a manual line break on the next line, I want to change that into a paragraph mark.

    I’ve used Find and Replace ( ^l^l ) ( ^p^p ) but am quite sure there must be a way to combine this with the macro below.

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = “^l”
    .Replacement.Text = ” ”
    .Forward = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Thank you very much,
    Curious

    Viewing 0 reply threads
    Author
    Replies
    • #1052122

      One age-old technique is to find all pairs of two adjacent line breaks, change those to an uncommon character, such as Chr(254), then run your replace for all remaining line breaks (to spaces or whatever), then change the Chr(254) back into paragraph breaks. The newer, lazier way is to get AutoFormat to handle your new text, but I don’t know whether that can be done in VBA.

      • #1052123

        Jefferson, Hi –

        Autoformat did not make any changes………………..But, thanks for the suggestion.

        • #1052134

          AutoFormat usually works for me. Could you attach a sample document where it doesn’t work?

          • #1052165

            Thanks for offering to see a sample, Hans.

            • #1052168

              Those lines are so short that AutoFormat assumes the line breaks are intentional. You can try the following code:

              With Selection.Find
              .ClearFormatting
              .Replacement.ClearFormatting
              ' Replace two line breaks with a paragraph end
              .Text = "^l^l"
              .Replacement.Text = "^p"
              .Execute Replace:=wdReplaceAll
              ' Replace single line breaks with a space
              .Text = "^l"
              .Replacement.Text = " "
              .Execute Replace:=wdReplaceAll
              End With

            • #1052225

              Hmm, I’ve been doing some tests, and I cannot get AutoFormat to remove superfluous line breaks consistently. I’ve used it successfully in the past, so I know it’s able to do it, but it doesn’t remove line breaks in several documents I tried it on. So Edit | Replace or a macro may be the best solutions.

            • #1052252

              Hans –

              Many thanks. Works perfectly, regardless of line length.

              Curious

    Viewing 0 reply threads
    Reply To: Manual line break macro (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: