Columns Collection Object

Multiple objects
Multiple objects

A collection of Column objects that represent the columns in a table.

Using the Columns Collection

Use the Columns property to return the Columns collection. The following example displays the number of Column objects in the Columns collection for the first table in the active document.

MsgBox ActiveDocument.Tables(1).Columns.Count

The following example creates a table with six columns and three rows and then formats each column with a progressively larger (darker) shading percentage.

Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=3, NumColumns:=6)
For Each col In myTable.Columns
    col.Shading.Texture = 2 + i
    i = i + 1
Next col

Use the Add method to add a column to a table. The following example adds a column to the first table in the active document, and then it makes the column widths equal.

If ActiveDocument.Tables.Count >= 1 Then
    Set myTable = ActiveDocument.Tables(1)
    myTable.Columns.Add BeforeColumn:=myTable.Columns(1)
End If

Use Columns(index), where index is the index number, to return a single Column object. The index number represents the position of the column in the Columns collection (counting from left to right). The following example selects the first column in the first table.


Properties | Application Property | Borders Property | Count Property | Creator Property | First Property | Last Property | NestingLevel Property | Parent Property | PreferredWidth Property | PreferredWidthType Property | Shading Property | Width Property

Methods | Add Method | AutoFit Method | Delete Method | DistributeWidth Method | Item Method | Select Method | SetWidth Method

Parent Objects | Range Object | Selection Object | Table Object

Child Objects | Borders Object | Column Object | Shading Object

See Also | Cells Collection Object | Rows Collection Object