Cell Object

Multiple objects
Multiple objects

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, or Cells(index), where index is the index number, to return a 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

The following example applies shading to the first cell in the first row.

ActiveDocument.Tables(1).Rows(1).Cells(1).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)


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 | BottomPadding Property | Column Property | ColumnIndex Property | Creator Property | FitText Property | Height Property | HeightRule Property | ID Property | LeftPadding Property | NestingLevel Property | Next Property | Parent Property | PreferredWidth Property | PreferredWidthType Property | Previous Property | Range Property | RightPadding Property | Row Property | RowIndex Property | Shading Property | Tables Property | TopPadding Property | VerticalAlignment Property | Width Property | WordWrap Property

Methods | AutoSum Method | Delete Method | Formula Method | Merge Method | Select Method | SetHeight Method | SetWidth Method | Split Method

Parent Objects | Column | Range | Row | Selection

Child Objects | Borders | Cell | Column | Range | Row | Shading | Tables

See Also | Column Object | Row Object