Table of contents
Collapse the table of content
Expand the table of content

Columns Object (Publisher)

office 365 dev account|Last Updated: 8/24/2017
3 Contributors

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


Use the Columns property of the Table object 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.

Sub CountColumns() 
 MsgBox "The number of columns in the table is " & _ 
End Sub

This example enters a bold number into each cell in the specified table. This example assumes 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 = _ 
 .Font.Bold = msoTrue 
 intCount = intCount + 1 
 End With 
 Next celTable 
 Next colTable 

End Sub

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 third column in the specified table.

Sub SelectColumns() 
End Sub

Use the Add method to add a column to a table. 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 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 _ 
 With colNew 
 .Width = 2 
 .Cells(1).Fill.ForeColor.RGB = RGB(Red:=202, Green:=202, Blue:=202) 
 End With 
End Sub




© 2017 Microsoft