Add Method (Tables Collection)

Applies To

Tables collection object.

Description

Adds a new, blank table to a document.

Syntax

expression.Add(Range, NumRows, NumColumns)

expression Required. An expression that returns a Tables object.

Range Required Range. The range where you want the table to appear. The table replaces the range, if the range isn't collapsed.

NumRows Required Long. The number of rows you want to include in the table.

NumColumns Required Long. The number of columns you want to include in the table.

See Also

Add method (Cells, Rows, and Columns collections).

Example

This example adds a blank table with three rows and four columns at the beginning of the active document.

Set myRange = ActiveDocument.Range(0, 0)
ActiveDocument.Tables.Add Range:=myRange, NumRows:=3, NumColumns:=4
This example adds a new, blank table with 6 rows and 10 columns at the end of the active document

Set MyRange = ActiveDocument.Content
MyRange.Collapse Direction:=wdCollapseEnd
ActiveDocument.Tables.Add Range:=MyRange, NumRows:=6, NumColumns:=10
This example adds a table with three rows and five columns to a new document and then inserts data into each cell in the table.

Set newDoc = Documents.Add
Set myTable = newDoc.Tables.Add(Selection.Range, 3, 5)
With myTable
For x = 1 to 3
    For y = 1 to 5
        .Cell(x,y).Range.InsertAfter "Cell " & x & "," & y
    Next y
Next x
.Columns.AutoFit
End With