Columns Object (Word)

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

Use the Columns property of a Range, Selection, or Table object to return a 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) 
 myTable.Columns.DistributeWidth 
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.

ActiveDocument.Tables(1).Columns(1).Select
Show:
© 2015 Microsoft