Columns object (Publisher)
A collection of Column objects that represent the columns in a table.
Remarks
Use the Columns property of the Table object to return the Columns collection.
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).
Use the Add method to add a column to a table.
Example
The following example displays the number of Column objects in the Columns collection for the first table in the active document.
Sub CountColumns()
MsgBox "The number of columns in the table is " & _
ActiveDocument.Pages(2).Shapes(1).Table.Columns.Count
End Sub
This example enters a bold number into each cell in the specified table. It assumes that the specified shape is a table and not another type of shape.
Sub CountCellsByColumn()
Dim shpTable As Shape
Dim colTable As Column
Dim celTable As Cell
Dim intCount As Integer
intCount = 1
Set shpTable = ActiveDocument.Pages(2).Shapes(1)
For Each colTable In shpTable.Table.Columns
For Each celTable In colTable.Cells
With celTable.Text
.Text = intCount
.ParagraphFormat.Alignment = _
pbParagraphAlignmentCenter
.Font.Bold = msoTrue
intCount = intCount + 1
End With
Next celTable
Next colTable
End Sub
The following example selects the third column in the specified table.
Sub SelectColumns()
ActiveDocument.Pages(2).Shapes(1).Table.Columns(3).Cells.Select
End Sub
This example adds a column to the specified table on the second page of the active publication, and then adjusts the width, merges the cells, and sets the fill color. This example assumes that the first shape is a table and not another type of shape.
Sub NewColumn()
Dim colNew As Column
Set colNew = ActiveDocument.Pages(2).Shapes(1).Table.Columns _
.Add(BeforeColumn:=3)
With colNew
.Width = 2
.Cells.Merge
.Cells(1).Fill.ForeColor.RGB = RGB(Red:=202, Green:=202, Blue:=202)
End With
End Sub
Methods
Properties
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.