Delete blank pagraphs in between tables using search and replace functionality

Posted on 2012-08-15
Last Modified: 2012-08-15
Dear Experts:

How can I delete blank paragraphs in between tables using the search and replace functionality.

The search for ^p and replace it with nothing approach does not seem to work.

I have attached a sample file for your convenience.

The result of this 'search and replace operation' or a VBA code should be that there is just one table left.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Question by:AndreasHermle
    LVL 76

    Accepted Solution

    Hi Andreas,

    It seems that the Find and Replace has been designed not to delete paragraphs in the case that they are keeping tables separated.
    You can do it with a macro:
    Sub JoinTables()
        Dim rng As Range
         Set rng = ActiveDocument.Range
         With rng.Find
            .Text = "^p"
            Do While .Execute
                If ActiveDocument.Range.End - rng.End < 2 Then
                    Exit Do
                End If
        End With
    End Sub

    Open in new window


    Author Closing Comment

    Hi Graham,

    wow, great coding, Graham! Thank you very much for your professional help.

    Regards, Andreas

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
    A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
    This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now