Class Cell (Word VBA)

The class Cell 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.

The main procedures of class Cell are Delete, Select, Cells.Add and Cells.Delete

Set

To use a Cell class variable it first needs to be instantiated, for example

Dim cll as Cell
Set cll = Selection.Cells(Index:=1)

The following procedures can be used to set variables of type Cell: Next, Previous, Cells.Add, Cells.Item, Table.Cell, Column.Cells, Range.Cells, Revision.Cells, Row.Cells and Selection.Cells

For Each

Here is an example of processing the Cell items in a collection.

Dim cll As Cell
For Each cll In Selection.Cells
 If cellLoop.ColumnIndex Mod 2 = 0 Then cellLoop.Column.Shading.Texture = wdTexture10Percent 
Next cll

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Column with its procedures Column and ColumnIndex
Row with its procedures Row and RowIndex

Methods

These are the main methods of the Cell class

Delete - Deletes a table cell or cells and optionally controls how the remaining cells are shifted.

Selection.Cells(1).Delete

Select - Selects the specified object.

Selection.Cells(1).Select

Cells.Add - Returns a Cell object that represents a cell added to a table.

Dim cll As Cell
Set cll = Selection.Cells.Add()

Cells.Delete - Deletes a table cell or cells and optionally controls how the remaining cells are shifted.

Selection.Cells.Delete

Other Methods

Formula - Inserts an = (Formula) field that contains the specified formula into a table cell.

Selection.Cells(1).Formula

SetHeight - Sets the height of table cells.

Dim lngRowHeight As Long: lngRowHeight =  
Selection.Cells(1).SetHeight RowHeight:=lngRowHeight, HeightRule:=wdRowHeightAtLeast

SetWidth - Sets the width of columns or cells in a table.

Selection.Cells(1).SetWidth ColumnWidth:=, RulerStyle:=wdAdjustFirstColumn

Split - Splits a single table cell into multiple cells.

Selection.Cells(1).Split

Cells.SetHeight - Sets the height of table cells.

Dim lngRowHeight As Long: lngRowHeight =  
Selection.Cells.SetHeight RowHeight:=lngRowHeight, HeightRule:=wdRowHeightAtLeast

Cells.SetWidth - Sets the width of columns or cells in a table.

Selection.Cells.SetWidth ColumnWidth:=, RulerStyle:=wdAdjustFirstColumn

Cells.Split - Splits a range of table cells.

Selection.Cells.Split

Properties

Borders returns a Borders collection that represents all the borders for the specified object.

Selection.Cells(1).Borders =

BottomPadding returns or sets the amount of space (in points) to add below the contents of a single cell or all the cells in a table.

Selection.Cells(1).BottomPadding =

FitText true if Microsoft Word visually reduces the size of text typed into a cell so that it fits within the column width.

Selection.Cells(1).FitText = True

Height returns or sets the height of the specified table cell.

Selection.Cells(1).Height =

HeightRule returns or sets a WdRowHeightRule constant that represents the rule for determining the height of the specified cells or rows.

Selection.Cells(1).HeightRule = wdRowHeightAtLeast

ID returns or sets the identifying label for the specified object when the current document is saved as a webpage.

Selection.Cells(1).ID =

LeftPadding returns or sets the amount of space (in points) to add to the left of the contents of a single cell or all the cells in a table.

Selection.Cells(1).LeftPadding =

NestingLevel returns the nesting level of the specified cell.

Dim lngNestingLevel As Long
lngNestingLevel = Selection.Cells(1).NestingLevel

Next returns a Cell object that represents the next table cell in the Cells collection.

Dim cllNext As Cell
Set cllNext = Selection.Cells(1).Next

Parent returns an object that represents the parent object of the specified Cell object.

Dim objParent As Object
Set objParent = Selection.Cells(1).Parent

PreferredWidth returns or sets the preferred width (in points or as a percentage of the window width) for the specified cell.

Selection.Cells(1).PreferredWidth =

PreferredWidthType returns or sets the preferred unit of measurement to use for the width of the specified cell.

Selection.Cells(1).PreferredWidthType = wdPreferredWidthAuto

Previous returns a Cell object that represents the previous table cell in the Cells collection.

Dim cllPrevious As Cell
Set cllPrevious = Selection.Cells(1).Previous

Range returns a Range object that represents the portion of a document that's contained in the specified object.

Dim rngRange As Range
Set rngRange = Selection.Cells(1).Range

RightPadding returns or sets the amount of space (in points) to add to the right of the contents of a single cell or all the cells in a table.

Selection.Cells(1).RightPadding =

Shading returns a Shading object that refers to the shading formatting for the specified object.

Dim shdShading As Shading
Set shdShading = Selection.Cells(1).Shading

Tables returns a Tables collection that represents all the nested tables inside the specified table cell.

Dim tblsTables As Tables
Set tblsTables = Selection.Cells(1).Tables

TopPadding returns or sets the amount of space (in points) to add above the contents of a single cell or all the cells in a table.

Selection.Cells(1).TopPadding =

VerticalAlignment returns or sets the vertical alignment of text in one or more cells of a table.

Selection.Cells(1).VerticalAlignment = wdCellAlignVerticalBottom

Width returns or sets the width of a table cell, in points.

Selection.Cells(1).Width =

WordWrap true if Microsoft Word wraps text to multiple lines and lengthens the cell so that the cell width remains the same.

Selection.Cells(1).WordWrap = True

Cells.Borders returns a Borders collection that represents all the borders for the specified object.

Selection.Cells.Borders =

Cells.Count returns the number of items in the Cells collection.

Dim lngCount As Long
lngCount = Selection.Cells.Count

Cells.Height returns or sets the height of the specified table cells.

Selection.Cells.Height =

Cells.HeightRule returns or sets a WdRowHeightRule constant that represents the rule for determining the height of the specified cells.

Selection.Cells.HeightRule = wdRowHeightAtLeast

Cells.NestingLevel returns the nesting level of the specified cells.

Dim lngNestingLevel As Long
lngNestingLevel = Selection.Cells.NestingLevel

Cells.Parent returns an object that represents the parent object of the specified Cells object.

Dim objParent As Object
Set objParent = Selection.Cells.Parent

Cells.PreferredWidth returns or sets the preferred width (in points or as a percentage of the window width) for the specified cells.

Selection.Cells.PreferredWidth =

Cells.PreferredWidthType returns or sets the preferred unit of measurement to use for the width of the specified cells.

Selection.Cells.PreferredWidthType = wdPreferredWidthAuto

Cells.Shading returns a Shading object that refers to the shading formatting for the specified object.

Dim shdShading As Shading
Set shdShading = Selection.Cells.Shading

Cells.VerticalAlignment returns or sets the vertical alignment of text in one or more cells of a table.

Selection.Cells.VerticalAlignment = wdCellAlignVerticalBottom

Cells.Width returns or sets the width of the table cells, in points.

Selection.Cells.Width =