Results 1 to 8 of 8
  1. #1
    4 Star Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    538
    Thanks
    0
    Thanked 1 Time in 1 Post

    Manual line break macro (2002)

    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

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Manual line break macro (2002)

    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.

  3. #3
    4 Star Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    538
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Manual line break macro (2002)

    Jefferson, Hi -

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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Manual line break macro (2002)

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

  5. #5
    4 Star Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    538
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Manual line break macro (2002)

    Thanks for offering to see a sample, Hans.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Manual line break macro (2002)

    Those lines are so short that AutoFormat assumes the line breaks are intentional. You can try the following code:
    <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</code>

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Manual line break macro (2002)

    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.

  8. #8
    4 Star Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    538
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Manual line break macro (2002)

    Hans -

    Many thanks. Works perfectly, regardless of line length.

    Curious

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •