Class Column (Word VBA)

The class Column represents a single table column. The Column object is a member of the Columns collection. The Columns collection includes all the columns in a table, selection, or range.

The main procedures of class Column are Delete, Select, Columns.Add, Columns.Delete and Columns.Select

Set

To use a Column class variable it first needs to be instantiated, for example

Dim clm as Column
Set clm = ActiveDocument.Range.Columns(Index:=1)

The following procedures can be used to set variables of type Column: Cell.Column, Next, Previous, Columns.Add, Columns.Item, Columns.First, Columns.Last, Range.Columns, Selection.Columns and Table.Columns

For Each

Here is an example of processing the Column items in a collection.

Dim clm As Column
For Each clm In ActiveDocument.Range.Columns
	
Next clm

Methods

These are the main methods of the Column class

Delete - Deletes the specified column.

ActiveDocument.Range.Columns(1).Delete

Select - Selects the specified table column.

ActiveDocument.Range.Columns(1).Select

Columns.Add - Returns a Column object that represents a column added to a table.

Dim clm As Column
Set clm = ActiveDocument.Range.Columns.Add()

Columns.Delete - Deletes the specified columns.

ActiveDocument.Range.Columns.Delete

Columns.Select - Selects the specified table columns.

ActiveDocument.Range.Columns.Select

Other Methods

SetWidth - Sets the width of a column in a table.

ActiveDocument.Range.Columns(1).SetWidth ColumnWidth:=, RulerStyle:=wdAdjustFirstColumn

Sort - Sorts the specified table column.

ActiveDocument.Range.Columns(1).Sort

Columns.SetWidth - Sets the width of columns in a table.

ActiveDocument.Range.Columns.SetWidth ColumnWidth:=, RulerStyle:=wdAdjustFirstColumn

Properties

Borders returns a Borders collection that represents all the borders for the specified object.

ActiveDocument.Range.Columns(1).Borders =

Cells returns a Cells collection that represents the table cells in a table column.

Dim cllsCells As Cells
Set cllsCells = ActiveDocument.Range.Columns(1).Cells

Index returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = ActiveDocument.Range.Columns(1).Index

IsFirst true if the specified column or row is the first one in the table.

Dim booIsFirst As Boolean
booIsFirst = ActiveDocument.Range.Columns(1).IsFirst

IsLast true if the specified column or row is the last one in the table.

Dim booIsLast As Boolean
booIsLast = ActiveDocument.Range.Columns(1).IsLast

NestingLevel returns the nesting level of the specified column.

Dim lngNestingLevel As Long
lngNestingLevel = ActiveDocument.Range.Columns(1).NestingLevel

Next returns the next column in a collection of table columns.

Dim clmNext As Column
Set clmNext = ActiveDocument.Range.Columns(1).Next

Parent returns an object that represents the parent object of the specified Column object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.Columns(1).Parent

PreferredWidth returns or sets the preferred width (in points or as a percentage of the window width) for the specified column.

ActiveDocument.Range.Columns(1).PreferredWidth =

PreferredWidthType returns or sets the preferred unit of measurement to use for the width of the specified table column.

ActiveDocument.Range.Columns(1).PreferredWidthType = wdPreferredWidthAuto

Previous returns the previous column in a collection of table columns.

Dim clmPrevious As Column
Set clmPrevious = ActiveDocument.Range.Columns(1).Previous

Shading returns a Shading object that refers to the shading formatting for the specified column.

Dim shdShading As Shading
Set shdShading = ActiveDocument.Range.Columns(1).Shading

Width returns or sets the width of the specified column, in points.

ActiveDocument.Range.Columns(1).Width =

Columns.Borders returns a Borders collection that represents all the borders for the specified columns.

ActiveDocument.Range.Columns.Borders =

Columns.Count returns a Long that represents the number of columns in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Range.Columns.Count

Columns.First returns a Column object that represents the first item in the Columns collection.

Dim clmFirst As Column
Set clmFirst = ActiveDocument.Range.Columns.First

Columns.Last returns a Column object that represents the last column in a table.

Dim clmLast As Column
Set clmLast = ActiveDocument.Range.Columns.Last

Columns.NestingLevel returns the nesting level of the specified columns.

Dim lngNestingLevel As Long
lngNestingLevel = ActiveDocument.Range.Columns.NestingLevel

Columns.Parent returns an object that represents the parent object of the specified Columns object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.Columns.Parent

Columns.PreferredWidth returns or sets the preferred width (in points or as a percentage of the window width) for the specified columns.

ActiveDocument.Range.Columns.PreferredWidth =

Columns.PreferredWidthType returns or sets the preferred unit of measurement to use for the width of the specified cells, columns, or table.

ActiveDocument.Range.Columns.PreferredWidthType = wdPreferredWidthAuto

Columns.Shading returns a Shading object that refers to the shading formatting for the specified table columns.

Dim shdShading As Shading
Set shdShading = ActiveDocument.Range.Columns.Shading

Columns.Width returns or sets the width of the specified columns, in points.

ActiveDocument.Range.Columns.Width =