Microsoft

Pro tip: Ways to convert Word tables to text

If you need to convert all the tables in a document to text, you could find yourself scrolling into oblivion. Instead, try one of these manual methods or a quick macro.

Working with Word

You can convert a table manually, but if your document has a lot of them, the manual process is tedious. Word complicates the process, because you can't select all of the tables at once the way you can other components. You can use Word's built-in selection tools to quickly select the tables one at a time (avoiding scrolling oblivion), but you'll still have to convert each one manually. In this article, I'll show you three ways to manually cycle through all the tables so you can convert them (or apply some other format change). Then, I'll show you a macro that converts all the tables for you.

Even if you don't need to convert tables, you may still learn some useful selection methods here. In addition, the macro can be easily adjusted to cycle through the Tables collection for reasons other than conversion. You can work with any Word document that contains a few tables, or you can download the sample .docm or .doc file. You can enter the macro yourself (it's short), or download the .cls module file.

Manual methods

The first manual selection method I want to show you is Word's Go To feature — [F5]:

  1. Press [F5].
  2. In the resulting Find And Replace dialog, choose Table from the Go To What list.
  3. Click Previous or Next, and Word will select a table accordingly (Figure A).
    Figure A
    Figure A
  4. To convert the selected table, click the contextual Layout tab, and then click Convert To Text in the Data group (the Find And Replace dialog will remain open). In Word 2003, choose Convert from the Table menu, and then select Table To Text.
  5. Select the appropriate separator (paragraph mark, tab, and so on) and click OK.
  6. Repeat steps 3 through 5 until you're done.
  7. Click Close to return to the document.

This method is easy, but the dialog can obstruct your view of the document, which might be a problem. If so, use the Select Browse Object. This button is at the bottom right corner of your screen, just below the vertical scroll bar. There's a small round dot with arrows just above and below. You might find this method of jumping from table to table a bit easier:

  1. Click the Select Browse Object button to display a palette of objects.
  2. From the palette, choose Browse by Table (Figure B).
    Figure B
    Figure B
  3. Click Previous or Next (the up and down arrows above and below the button, respectively).
  4. When Word selects the table, repeat steps 4 and 5 above.
  5. Continue until you're done.

The last method I want to show you, the Find feature, is probably familiar to you (but isn't supported by Word 2003):

  1. On the Home tab, click Find in the Editing group, and Word will open the Navigation pane.
  2. Choose Tables from the Find Options drop-down menu (Figure C).
    Figure C
    Figure C
  3. Repeat steps 4 and 5 from the Go To method to convert the selected table.
  4. To select the next table, click the Next Search Result button in the Navigation pane (Figure D).
    Figure D
    Figure D
  5. Continue until you're done.

The cycling macro

All three methods eliminate the messy business of scrolling through all the text between each table, but you still have to manually convert each table. Keep in mind that you can use all three of these techniques to find other objects. Now, let's look at the macro that converts all of the tables with a click:

Sub ConvertAllTablesToText()
    'Convert all the tables in current document to text.
    Dim tbl As Table
    For Each tbl In ActiveDocument.Tables
        tbl.ConvertToText Separator:=wdSeparateByTabs
    Next
End Sub 

To use this macro, you'll need to enter it into the document's ThisDocument module as follows:

  1. With the document open, press [Alt]+[F11] to open the Visual Basic Editor.
  2. Open the document's ThisDocument module using the VBE Project Explorer (to the left). If it isn't open, press [Ctrl]+[R] or choose Project Explorer from the View menu.
  3. Enter the macro (don't copy and paste from this web page; you must type it or download the .cls file).
  4. To run the macro, return to the document, and click the Developer tab.
  5. Click Macros in the Code group.
  6. In the resulting dialog, identify the macro (Figure E).
    Figure E
    Figure E
  7. Click Run.

The macro cycles through all of the tables in the Tables collection and executes the ConvertToText method against each. I used the tab separator, but you can change this constant to suit your tables:

  • wdSeparateByTabs
  • wdSeparateByCommas
  • wdSeparateByDefaultListSeparator
  • wdSeparateByParagraphs

Worth noting

You can replace the convert statement in the For loop and use this macro to make formatting, style, or property changes to all of the tables in the same document. In addition, the selection methods I've highlighted here can be used in numerous situations.

Send me your question about Office

I answer readers' questions when I can, but there's no guarantee. When contacting me, be as specific as possible. For instance, "Please troubleshoot my workbook and fix what's wrong" probably won't get a response, but "Can you tell me why this formula isn't returning the expected results?" might. I'm not reimbursed by TechRepublic for my time or expertise, nor do I ask for a fee from readers. You can contact me at susansalesharkins@gmail.com.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

Editor's Picks

Free Newsletters, In your Inbox