Copying All Tables to a New Document

by Allen Wyatt
(last updated December 13, 2014)

5

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

Conditionally Displaying a Message Box

You can, from within your macros, easily display a message box containing a message of your choice. If you want to display ...

Discover More

Monthly Close-Out Dates

If your company closes out its accounting months at the end of each calendar quarter, figuring out the proper closing dates ...

Discover More

Understanding Grayscale Images

Word allows you to easily add images to your documents. For documents intended for monochrome printers, grayscale images are ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Using Outline Numbering in a Table

Can you put a numbered outline in a table? Yes, you can. But Word is rather prickly when it comes to using the keyboard to ...

Discover More

Printing Only Selected Rows from a Table

Tables are a great way to organize the information in a document. If your table gets quite long, you may not want to print ...

Discover More

Creating a Split Page

In WordPerfect terminology, a split page allows you to put information side-by-side on opposite halves of the page. If you ...

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 6 - 0?

2017-11-22 06:16:16

Yechiel

hi
I want to copy a table from a word document into a sheet as follow:
each new line in the word should be copy to the new line in the sheet, but
if any cell in the word line contains ^p (paragraph mark) then 2 new lines should be added.

Thanks'
Yechiel


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.