Cells Property

Microsoft Word Visual Basic

Cells Property

       

Returns a Cells collection that represents the table cells in a column, row, selection, or range. Read-only.

For information about returning a single member of a collection, see Returning an Object from a Collection.

Example

This example creates a 3x3 table and assigns a sequential cell number to each cell in the table.

Set newDoc = Documents.Add 
Set myTable = newDoc.Tables.Add(Selection.Range, 3, 3)
i = 1
For Each c In myTable.Range.Cells
    c.Range.InsertAfter "Cell " & i
    i = i + 1
Next c

This example sets the current cell's background color to red.

If Selection.Information(wdWithInTable) = True Then
    Selection.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
Else
    MsgBox "The insertion point is not in a table."
End If