Solved

How do I create a macro that removes empty carriage returns from a Word table cell?

Posted on 2008-11-02
2
357 Views
Last Modified: 2010-04-21
I'm a technical writer and often edit people's Word documents. A common formatting issue is that people place extra carriage returns in their tables. Word has an excellent search/replace facility, but it doesn't have a code for finding the end-of-table-cell character. So, I can remove all double carriage returns (¶¶, or ^p^p) in a cell, but can't remove that final ¶ before the end of the cell. I'd like to create a macro to find and replace "¶ followed by an end-of-table-cell character" with just the end-of-table-cell character. I know this has got to be an extremely simple bit of code but I'm not familiar enough with VBA yet to know what to do. Thanks in advance for any suggestions.
0
Comment
Question by:calyx_teren
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 125 total points
ID: 22863672
I think this will help you.
Sub TidyCells()

    Dim cl As Cell

    Dim tbl As Table

    Dim rng As Range

    

    For Each tbl In ActiveDocument.Tables

        For Each cl In tbl.Range.Cells

            Set rng = cl.Range

            rng.MoveEnd wdCharacter, -1 'moves back from cell formatting character

            Do While Right$(rng.Text, 1) = vbCr 'move back over paragraph marks

                rng.MoveEnd wdCharacter, -1

            Loop

            cl.Range.Text = rng.Text

        Next cl

    Next tbl

End Sub

Open in new window

0
 

Author Closing Comment

by:calyx_teren
ID: 31512516
Thank you very much. This will save me enormous amounts of tedious work, and I learned more about VBA in the bargain. Much appreciated.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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 a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

746 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

7 Experts available now in Live!

Get 1:1 Help Now