• Delete all blank lines (97)

    Author
    Topic
    #409242

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #870669

      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.

      • #870705

        … simply doing a replace will do it

        Search for ^p^p and replace with ^p

        • #871703

          …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)

          • #871731

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

            • #872417

              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.

            • #872418

              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.

          • #871732

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

        • #871704

          …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)

      • #870706

        … simply doing a replace will do it

        Search for ^p^p and replace with ^p

    • #870670

      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.

    Viewing 1 reply thread
    Reply To: Delete all blank lines (97)

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

    Your information: