Columns Collection Object
Description
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)
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
Properties
Application property, Borders property, Count property, Creator property, First property, Last property, Parent property, Shading property, Width property.
Methods
Add method (Cells, Rows, and Columns collections), AutoFit method, Delete method, DistributeWidth method, Item method, Select method, SetWidth method.
See Also
Cells collection object, Rows collection object.