Share via


Column Object

Word Developer Reference

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.

Remarks

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 column one in table one in the active document.

Visual Basic for Applications
  ActiveDocument.Tables(1).Columns(1).Select

Use the Column property with a Cell object to return a Column object. The following example deletes the text in cell one, inserts new text, and then sorts the entire column.

Visual Basic for Applications
  With ActiveDocument.Tables(1).Cell(1, 1)
    .Range.Delete
    .Range.InsertBefore "Sales"
    .Column.Sort
End With

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.

Visual Basic for Applications
  If ActiveDocument.Tables.Count >= 1 Then
    Set myTable = ActiveDocument.Tables(1)
    myTable.Columns.Add BeforeColumn:=myTable.Columns(1)
    myTable.Columns.DistributeWidth
End If

Remarks

Use the Information property with a Selection object to return the current column number. The following example selects the current column and then displays the column number in a message box.

Visual Basic for Applications
  If Selection.Information(wdWithInTable) = True Then
    Selection.Columns(1).Select
    MsgBox "Column " _
        & Selection.Information(wdStartOfRangeColumnNumber)
End If

See Also