Cells Collection Object

Description

A collection of Cell objects in a table column, table row, selection, or range.

Using the Cells Object

Use the Cells property to return the Cells collection. The following example formats the cells in the first row in table one in the active document to be 30 points wide.

ActiveDocument.Tables(1).Rows(1).Cells.Width = 30
The following example returns the number of cells in the current row.

num = Selection.Rows(1).Cells.Count
Use the Add method to add a Cell object to the Cells collection. You can also use the InsertCells method of the Selection object to insert new cells. The following example adds a cell before the first cell in myTable.

Set myTable = ActiveDocument.Tables(1)
myTable.Range.Cells.Add BeforeCell:=myTable.Cell(1, 1)
Use Cell(row, column), where row is the row number and column is the column number, to return the Cell object. The following example applies shading to the second cell in the first row in table one.

Set myCell = ActiveDocument.Tables(1).Cell(Row:=1, Column:=2)
myCell.Shading.Texture = wdTexture20Percent
Remarks

Use the Add method with the Rows or Columns collection to add a row or column of cells. The following example adds a column to the first table in the active document and then inserts numbers into the first column.

Set myTable = ActiveDocument.Tables(1)
Set aColumn = myTable.Columns.Add(BeforeColumn:=myTable.Columns(1))
For Each aCell In aColumn.Cells
    aCell.Range.Delete
    aCell.Range.InsertAfter num + 1
    num = num + 1
Next aCell
Properties

Application property, Borders property, Count property, Creator property, Height property, HeightRule property, Parent property, Shading property, VerticalAlignment property, Width property.

Methods

Add method (Cells, Rows, and Columns collections), AutoFit method, Delete method, DistributeHeight method, DistributeWidth method, Item method, Merge method, SetHeight method, SetWidth method, Split method.

See Also

Columns collection object, Rows collection object.