Solved

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

Posted on 2008-11-02
2
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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…

738 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