Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Empty para / Table (Word xp)

    I have code that I often use to delete empty paragraph at the end of a document. There is a problem, however, if there is only one empty paragraph at the end of a document AND it is preceded by a table. The code doesn't raise an error... it just hangs. Occasionally, Word is "not responding."

    This is the code I use; what would be the most efficient way of touching the lone paragraph following a table?

    With ActiveDocument
    Do While .Paragraphs(.Paragraphs.Count).Range.Text = vbCr
    .Paragraphs(.Paragraphs.Count).Range.Delete
    Loop
    End With

    Thanks,
    Richard Barrett

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Empty para / Table (Word xp)

    This seems to do the trick for me...
    <code>
    With ActiveDocument
    Do While .Paragraphs(.Paragraphs.Count).Range.Text = vbCr
    If .Paragraphs(.Paragraphs.Count - 1).Range.Information(wdWithInTable) Then Exit Do
    .Paragraphs(.Paragraphs.Count).Range.Delete
    Loop
    End With
    </code>
    StuartR

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Empty para / Table (Word xp)

    Thank you. That makes great sense. When doing a Find/Replace for, let's say four paragraphs to be replaced with one (to tighten up spacing in a document), Word doesn't find four paragraphs if they happen to come between two tables. It seems that the first and (maybe the) fourth paragraphs in my sample case here are "attached" to a table. Can you think of anyway to get around that?

    Thanks.

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

    Re: Empty para / Table (Word xp)

    See Remove all empty paragraphs from a document for some ideas on deleting paragraphs between tables.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Empty para / Table (Word xp)

    Perfect. Thank you.

Posting Permissions

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