Add Method (Cells, Rows, and Columns Collections)
Applies To
Cells collection object, Columns collection object, Rows collection object.
Description
Adds a cell, row, or column to a table.
Syntax 1
expression.Add(BeforeCell)
Syntax 2
expression.Add(BeforeColumn)
Syntax 3
expression.Add(BeforeRow)
expression Required. An expression that returns a Cells object (Syntax 1), Columns object (Syntax 2), or Rows object (Syntax 3).
BeforeCell Optional Variant. A Cell object that represents the cell that will appear immediately to the right of the new cell or cells.
BeforeColumn Optional Variant. A Column object that represents the column that will appear immediately to the right of the new column.
BeforeRow Optional Variant. A Row object that represents the row that will appear immediately below the new row.
See Also
Add method (Tables collection), InsertCells method.
Example
This example inserts a new row before the first row in the selection.
If Selection.Information(wdWithInTable) = True Then
Selection.Rows.Add BeforeRow:= Selection.Rows(1)
End If
This example creates a table with two columns and two rows in the active document and then adds another column before the first column. The width of the new column is set at 1.5 inches.
Set myTable = ActiveDocument.Tables.Add(Selection.Range, 2, 2)
Set newCol = myTable.Columns.Add(BeforeColumn:= myTable.Columns(1))
newCol.SetWidth ColumnWidth:=InchesToPoints(1.5), RulerStyle:=wdAdjustNone
This example adds a row to the first table and then inserts the text "Cell" into this row.
counter = 1
Set myTable = ActiveDocument.Tables(1)
Set newrow = myTable.Rows.Add(BeforeRow:=myTable.rows(1))
For Each c In newrow.Cells
c.Range.InsertAfter Text:="Cell " & counter
counter = counter + 1
Next c