ConvertToText Method

Applies To

Row object, Rows collection object, Table object.

Description

Converts a table to text and returns a Range object that represents the delimited text.

Syntax

expression.ConvertToText(Separator)

expression Required. An expression that returns a Row, Rows, or Table object.

Separator Optional Variant. The character that delimits the converted columns (paragraph marks delimit the converted rows). Can be one of the following WdTableFieldSeparator constants: wdSeparateByCommas, wdSeparateByDefaultListSeparator, wdSeparateByParagraphs, or wdSeparateByTabs. The default value is wdSeparateByTabs.

Remarks

When you apply the ConvertToText method to a Table object, the object is deleted. To maintain a reference to the converted contents of the table, you must assign the Range object returned by the ConvertToText method to a new object variable. In the following example, the first table in the active document is converted to text and then formatted as a bulleted list.

Set myTable = ActiveDocument.Tables(1)
Set aRange = myTable.ConvertToText(Separator:=wdSeparateByParagraphs)
aRange.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries _
    (wdBulletGallery).ListTemplates(1)
See Also

ConvertToTable method, DefaultTableSeparator property, Tables property.

Example

This example creates a table and then converts it to text by using tabs as separator characters.

Set newDoc = Documents.Add
Set myTable = newDoc.Tables.Add(Range:=Selection.Range, _
    NumRows:=3, NumColumns:=3)
i = 1
For Each aCell In myTable.Range.Cells
    aCell.Range.InsertAfter "Cell " & i
    i = i + 1
Next aCell
MsgBox "Click OK to convert table to text."
Set myRange = myTable.ConvertToText(Separator:=wdSeparateByTabs)
This example converts the table that contains the selection to text, with spaces between the columns.

If Selection.Information(wdWithInTable) = True Then 
    Selection.Tables(1).ConvertToText Separator:=" "
Else
    MsgBox "The insertion point is not in a table."
End If