Cell Object (Word)
Published: July 16, 2012
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.
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.
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
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.