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

Deleting Footnotes and Endnotes

Deleting either footnotes or endnotes is a simple process. Just select the reference mark and delete it. Assuming you are ...

Discover More

Deleting a Range of Pages

Need to delete a range of pages out of the middle of your document? It's easy to do using editing techniques you already know ...

Discover More

Protect Your Document Templates

If you want to protect your templates from accidental changes, the best way to do so is by using Windows instead of Word. ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Selecting a Table

There are a couple of different ways you can select an entire table in Word. The methods and shortcuts are described in this ...

Discover More

Formatting Lots of Tables

Do you need a quick way to format your tables? Believe it or not, there are several tools you can use from Word's arsenal to ...

Discover More

Changing Spacing Between Table Cells

Need to adjust the space between individual cells in a table? Word gives you a good deal of control over this spacing, as ...

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 8Mpixels. 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 7 - 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.