Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete all blank lines (97)

    Hello all,

    I looking for a macro that will delete all blank lines (Line with only a paragraph mark) from a Word document.
    (Because I have a Document full of data to be converted to Excel, but there are a lot of empty lines that I don't need, and now the document is to big to import in Excel, without these emply lines it should fit)
    Who can help me?

  2. #2
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete all blank lines (97)

    I already found a solution:

    Sub DeleteBadLines()
    Application.ScreenUpdating = False
    Dim BadLine As Long
    With ActiveDocument
    For BadLine = .Paragraphs.Count To 1 Step -1
    If Len(.Paragraphs(BadLine).Range.Text) < 2 Then
    .Paragraphs(BadLine).Range.Delete
    End If
    Next
    End With
    Application.ScreenUpdating = True
    End Sub

    Tanks anyway for thinking with me.

  3. #3
    5 Star Lounger
    Join Date
    Oct 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    621
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete all blank lines (97)

    ... simply doing a replace will do it

    Search for ^p^p and replace with ^p

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete all blank lines (97)

    ...although you may need to do the replace several times if there are consecutive blank lines (at least that's how it works in Word XP)

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete all blank lines (97)

    You can use wildcards &:
    Find: ^13{1,}
    Replace all: ^p
    Then you only need to do it once.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Delete all blank lines (97)

    Patrick's solution is handy for removing a single paragraph mark inside table cells though - the search and replace methods don't do this.

    It doesn't however fix a table cell that has some text followed by a return and then nothing. To catch those little critters is more complex as you need to delete the paragraph mark which precedes that paragraph without changing the previous paragraph's style.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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