Copying All Tables to a New Document

by Allen Wyatt
(last updated December 13, 2014)

4

Tables are a great way to present many types of information. In fact, I've seen some documents that consist almost entirely of tables. If you do a lot of work with tables, you may (at some point) want to copy all the tables from one document to a brand new document. This could be helpful if you have tabular information that needs to be available in the new document, but you don't need the rest of the information from the original document.

The easiest way to do this type of copying is by using a macro. Fortunately, all the tables in a document are made available to VBA through the Tables collection. That means you can step through each item in the collection (each item will be an individual table) and then copy it.

Sub CopyTables()
    Dim Source As Document
    Dim Target As Document
    Dim tbl As Table
    Dim tr As Range

    Set Source = ActiveDocument
    Set Target = Documents.Add

    For Each tbl In Source.Tables
        Set tr = Target.Range
        tr.Collapse wdCollapseEnd
        tr.FormattedText = tbl.Range.FormattedText
        tr.Collapse wdCollapseEnd
        tr.Text = vbCrLf
    Next
End Sub

The macro, once run, creates a brand new document (Target) and copies the tables from the original document (Source) into the new one. (The source document is whatever document was active when you ran the macro.) The macro places a blank line between each table in the Target document. If you don't want the blank line, then remove or comment out the line just before the Next statement.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13338) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting Fields

Fields are used for a variety of dynamic purposes in a document. There are a couple of ways you can easily insert fields, as ...

Discover More

Inserting the Document Revision Number

Need to know how many times your document has been saved? Word keeps track of this information, and makes it easily ...

Discover More

Losing Formatting

When you save a workbook, you expect Excel to remember the formatting you applied in the worksheets in that workbook. If ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Setting Table Values to Three Decimal Places

If you import information into a document from another program, the values you import may not be exactly to your liking. For ...

Discover More

Table Numbers are Skipped

What do you do if you add numbered captions to an element of your document (such as tables) and Word skips a number? There ...

Discover More

Jumping to a Table Row

Need to jump to a particular row in a table? Word provides an easy way to jump to all sorts of things, but it doesn't seem ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 2?

2016-03-02 17:07:10

Dennus

Thanks for the help. It saved me a lot of time.


2016-01-28 04:49:55

Richard

Hello Allen

This macro is really helping me with a report I need to do for a project. The report consists of tables and associated sales text and is given to a customer.

Afterwards the tables will be used by another department who do not need the text so this helps me give them just that.

However is there an amendment i can make to change the target from a new blank word document to an existing world file (which would have a title and formatting in place).

I have tried replacing 'Documents.Add' with 'tmpName = ActiveDocument.AttachedTemplate.FullName
Documents.Add Template:=tmpName, NewTemplate:=True' but I don't think I am adding it in correctly are you able to explain how I could add this function?

Many Thanks
Richard


2014-12-16 23:41:12

Ram Ashish

Hello Allen

It is very useful macro but it copying tables only.It will be great if it copying table title and note and source.

thanks and regards
Ram Ashish


2014-12-15 09:05:33

Philip Ulanowsky

Hello, Allen, and Christmas greetings to you and your family.

I really like the idea of copying all the tables to another document. In my proposal work, I sometimes end up copying tables from a source document, into which someone has just cut-and- pasted them from who knows where; placing them in a black doc for style stripping (Clear all, Ctrl w/space and Q, and Alt+Ctrl_u); then pasting them into the target and applying a custom table style.

As you know, Word tables, especially very long ones, can carry with them all (and can even disable application of custom styles from the QAT, as occasionally happens to me, sometimes even after stripping; who knows where Word's coding hides the key to that little gremlin!).

Your macro would be additionally useful, therefore, if, after copying all the tables to a new document, it would perform the stripping operations. This could be, perhaps, a separate macro, but a one-shot sweep would be great.

Best wishes,
Philip


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.