Word VBA: Converting a Table To Text

This Word VBA macro converts a selected table to text.

Macro Example

Sub ConvertToText_SelectedTable()

  Selection.Tables(1).ConvertToText Separator:=wdSeparateByTabs

End Sub

Description

[Application.]Selection

  Selection...

The [Application.]Selection property returns the Selection object that represents a selected range on a Word document.

obj-Word-Application-Selection

Because the Selection property is a member of the Word.Global class, we can omit the Application property.

obj-Word-Global-Selection

Selection.Tables

  Selection.Tables...

The Selection.Tables property returns a Tables collection object in a selected range.

obj-Word-Selection-Tables

Tables(1) (Tables.Item(1))

  Selection.Tables(1)...

The Tables.Item method returns an individual Table object in the Tables collection object. And the Tables.Item(1) represents the first table.

obj-Word-Tables-Item

The Item method is a default member of the Tables collection object. We can see a little blue marble beside its icon in the Object Browser.
So we can omit the .Item.

Tables(1).ConvertToText (Table.ConvertToText)

  Selection.Tables(1).ConvertToText

We can convert a table to text by the Table.ConvertToText method.

obj-Word-Table-ConvertToText

And we can specify the character that delimits the converted columns by the Separator parameter that can be any WdTableFieldSeparator constants.

obj-Word-WdTableFieldSeparator

In this macro, I am setting the wdSeparateByTabs to the Separator parameter. So the converted columns will be delimit by tabs.

Sub ConvertToText_SelectedTable()

  Selection.Tables(1).ConvertToText Separator:=wdSeparateByTabs

End Sub

Properties

http://www.relief.jp/itnote/archives/word-macro-tables-convert-to-text.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007