ConvertToTable Method
Converts text within a range or selection to a table. Returns the table as a Table object.
expression**.ConvertToTable**(Separator, NumRows, NumColumns, InitialColumnWidth, Format, ApplyBorders, ApplyShading, ApplyFont, ApplyColor, ApplyHeadingRows, ApplyLastRow, ApplyFirstColumn, ApplyLastColumn, AutoFit, AutoFitBehavior, DefaultTableBehavior)
expression Required. An expression that returns a Range or Selection object.
WdTableFieldSeparator
WdTableFieldSeparator can be one of these WdTableFieldSeparator constants. |
wdSeparateByCommas |
wdSeparateByDefaultListSeparator |
wdSeparateByParagraphs |
wdSeparateByTabs |
NumRows Optional Variant. The number of rows in the table. If this argument is omitted, Microsoft Word sets the number of rows, based on the contents of the range or selection.
NumColumns Optional Variant. The number of columns in the table. If this argument is omitted, Word sets the number of columns, based on the contents of the range or selection.
InitialColumnWidth Optional Variant. The initial width of each column, in points. If this argument is omitted, Word calculates and adjusts the column width so that the table stretches from margin to margin.
WdTableFormat
Can be one of the following WdTableFormat constants: |
wdTableFormat3DEffects1 |
wdTableFormat3DEffects2 |
wdTableFormat3DEffects3 |
wdTableFormatClassic1 |
wdTableFormatClassic2 |
wdTableFormatClassic3 |
wdTableFormatClassic4 |
wdTableFormatColorful1 |
wdTableFormatColorful2 |
wdTableFormatColorful3 |
wdTableFormatColumns1 |
wdTableFormatColumns2 |
wdTableFormatColumns3 |
wdTableFormatColumns4 |
wdTableFormatColumns5 |
wdTableFormatContemporary |
wdTableFormatElegant |
wdTableFormatGrid1 |
wdTableFormatGrid2 |
wdTableFormatGrid3 |
wdTableFormatGrid4 |
wdTableFormatGrid5 |
wdTableFormatGrid6 |
wdTableFormatGrid7 |
wdTableFormatGrid8 |
wdTableFormatList1 |
wdTableFormatList2 |
wdTableFormatList3 |
wdTableFormatList4 |
wdTableFormatList5 |
wdTableFormatList6 |
wdTableFormatList7 |
wdTableFormatList8 |
wdTableFormatNone |
wdTableFormatProfessional |
wdTableFormatSimple1 |
wdTableFormatSimple2 |
wdTableFormatSimple3 |
wdTableFormatSubtle1 |
wdTableFormatSubtle2 |
wdTableFormatWeb1 |
wdTableFormatWeb2 |
wdTableFormatWeb3 |
ApplyBorders Optional Variant. True to apply the border properties of the specified format.
ApplyShading Optional Variant. True to apply the shading properties of the specified format.
ApplyFont Optional Variant. True to apply the font properties of the specified format.
ApplyColor Optional Variant. True to apply the color properties of the specified format.
ApplyHeadingRows Optional Variant. True to apply the heading-row properties of the specified format.
ApplyLastRow Optional Variant. True to apply the last-row properties of the specified format.
ApplyFirstColumn Optional Variant. True to apply the first-column properties of the specified format.
ApplyLastColumn Optional Variant. True to apply the last-column properties of the specified format.
AutoFit Optional Variant. True to decrease the width of the table columns as much as possible without changing the way text wraps in the cells.
WdAutoFitBehavior
WdAutoFitBehavior can be one of these WdAutoFitBehavior constants. |
wdAutoFitContent |
wdAutoFitFixed |
wdAutoFitWindow |
WdDefaultTableBehavior
WdDefaultTableBehavior can be one of these WdDefaultTableBehavior constants. |
wdWord8TableBehavior Disables AutoFit. Default. |
wdWord9TableBehavior Enables AutoFit. |
Example
As it applies to the Range object.
This example converts the first three paragraphs in the active document to a table.
Set aDoc = ActiveDocument
Set myRange = aDoc.Range(Start:=aDoc.Paragraphs(1).Range.Start, _
End:=aDoc.Paragraphs(3).Range.End)
myRange.ConvertToTable Separator:=wdSeparateByParagraphs
As it applies to the Selection object.
This example inserts text at the insertion point and then converts the comma-delimited text to a table with formatting.
With Selection
.Collapse
.InsertBefore "one, two, three"
.InsertParagraphAfter
.InsertAfter "one, two, three"
.InsertParagraphAfter
End With
Set myTable = _
Selection.ConvertToTable(Separator:=wdSeparateByCommas, _
Format:=wdTableFormatList8)
Applies to | Range Object | Selection Object
See Also | ConvertToText Method | DefaultTableSeparator Property