Cell Object

Description

Represents a single table cell. The Cell object is a member of the Cells collection. The Cells collection represents all the cells in the specified object.

Using the Cell Object

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.

Set myCell = ActiveDocument.Tables(1).Cell(Row:=1, Column:=2)
myCell.Shading.Texture = wdTexture20Percent
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)
The following example sets a range (myRange) that references the first two cells in the first table. After the range is set, the cells are combined by the Merge method.

Set myTable = ActiveDocument.Tables(1)
Set myRange = ActiveDocument.Range(myTable.Cell(1, 1).Range.Start, _
    myTable.Cell(1, 2).Range.End)
myRange.Cells.Merge
Remarks

Use the Add method with the Rows or Columns collection to add a row or column of cells.

Use the Information property with a Selection object to return the current row and column number. The following example changes the width of the first cell in the selection and then displays the cell's row number and column number.

If Selection.Information(wdWithInTable) = True Then
    With Selection
        .Cells(1).Width = 22
        MsgBox "Cell " & .Information(wdStartOfRangeRowNumber) & "," _
            & .Information(wdStartOfRangeColumnNumber)
    End With
End If
Properties

Application property, Borders property, Column property, ColumnIndex property, Creator property, Height property, HeightRule property, Next property, Parent property, Previous property, Range property, Row property, RowIndex property, Shading property, VerticalAlignment property, Width property.

Methods

AutoSum method, Delete method, Formula method, Merge method, Select method, SetHeight method, SetWidth method, Split method.

See Also

Column object, Row object.