ConvertToTable
This method converts text within a range to a table. Returns the table as a Table object.
Syntax
expression.ConvertToTable (Separator, NumRows, NumColumns, InitialColumnWidth, Format, ApplyBorders, ApplyShading, ApplyFont, ApplyColor, ApplyHeadingRows, ApplyLastRow, ApplyFirstColumn, ApplyLastColumn, AutoFit, AutoFitBehavior, DefaultTableBehavior)
Parameters
- Separator: Specifies the character used to separate text into cells. It can be a character or one of the following WdTableFieldSeparator constant. If this argument is not specified, the value of the DefaultTableSeparator property is used as shown in the code example:
- wdSeparateByDefaultListSeparator
- wdSeparateByCommas
- wdSeparateByParagraphs
- wdSeparateByTabs
- wdSeparatorColon
- wdSeparatorEmDash
- wdSeparatorEnDash
- wdSeparatorHyphen
- wdSeparatorPeriod
- NumRows: The number of rows in the table. If this argument is not specified, Microsoft Word sets the number of rows, based on the contents of the selected range.
- NumColumns: The number of columns in the table. If this argument is removed, Microsoft Word sets the number of columns, based on the contents of the given range.
- InitialColumnWidth: The initial width of each column, It is referred in points. If this argument is removed, Microsoft Word calculates and adjusts the column width so that the table stretches from margin to margin.
- Format: Specifies one of the predefined formats listed in the Table AutoFormat dialog box. It can be one of the WdTableFormat constants as listed below:
- wdTableFormat3DEffects1 to wdTableFormat3DEffects3
- wdTableFormatClassic1 to wdTableFormatClassic4
- wdTableFormatColorful1 to wdTableFormatColorful3
- wdTableFormatColumns1 to wdTableFormatColumn4
- wdTableFormatContemporary
- wdTableFormatElegant
- wdTableFormatGrid1 to wdTableFormatGrid7
- wdTableFormatList1 to wdTableFormatList8
- wdTableFormatNone
- wdTableFormatProfessional
- wdTableFormatSimple1 to wdTableFormatSimple3
- wdTableFormatSubtle1
- wdTableFormatSubtle2
- wdTableFormatWeb1 to wdTableFormatWeb3
- ApplyBorders: True to apply the border.
- ApplyShadding: True to apply the shading.
- ApplyFont: True to apply the font.
- ApplyColor: True to apply the color.
- ApplyHeadingRows: True to apply the heading-row.
- ApplyLastRow: True to apply the last-row.
- ApplyFirstColumn: True to apply the first-column.
- ApplyLastColumn: True to apply the last-column.
- AutoFit: True to decrease the width of the table columns as much as possible without changing the way text wraps in the cells.
- AutoFitBehavior: Sets the AutoFit rules for how Microsoft Word sizes a table. It can be one of the following WdAutoFitBehavior constant. If Default Table Behavior is wdWord8TableBehavior, this argument is ignored.
- wdAutoFitContent
- wdAutoFitFixed
- wdAutoFitWindow
- DefaultTableBehavior: Sets a value that specifies whether Microsoft Word automatically resizes cells in a table to fit the contents (AutoFit). It can be one of the WdDefaultTableBehavior constant:
- wdWord8TableBehavior
- wdWord9TableBehavior
Note: all parameters are optional and variant data type by nature for ConvertToTable method
Example

Code example
Public Sub ConvertToTable() 'Grabe Selection Dim oRange As Range Set oRange = Selection.Range 'Declare a table object to hold the result Dim oTable As Table 'Query to convert text to table Set oTable = oRange.ConvertToTable(Separator:=wdSeparatorEmDash, Format:=wdTableFormatApplyBorders, ApplyBorders:=True, ApplyHeadingRows:=True) oTable.Select 'memory cleanup Set oRange = Nothing Set oTable = Nothing End Sub
Output

Please leave your comments or queries under comment section also please do subscribe to out blogs to keep your self upto date.