多种对象![]() ![]() ![]() |
代表单个表格列。Column 对象是 Columns 集合的一个元素。Columns 集合包括某一表格、选定内容或区域中的所有列。
使用 Columns(index) 可返回单独的 Column 对象,其中 index 为索引序号。索引序号代表该列在 Columns 集合中的位置(从左至右计算)。
下列示例选定活动文档中的表格 1 的第一列。
ActiveDocument.Tables(1).Columns(1).Select
用 Cell 对象的 Column 属性可返回一个 Column 对象。下列示例删除单元格 1 中的文字,插入新文字,然后对该列进行排序。
With ActiveDocument.Tables(1).Cell(1, 1)
.Range.Delete
.Range.InsertBefore "Sales"
.Column.Sort
End With
用 Add 方法可在表格中添加一列。下列示例为活动文档的第一张表格中添加一列,然后将列宽设置为相等。
If ActiveDocument.Tables.Count >= 1 Then
Set myTable = ActiveDocument.Tables(1)
myTable.Columns.Add BeforeColumn:=myTable.Columns(1)
myTable.Columns.DistributeWidth
End If
用 Selection 对象的 Information 属性可返回当前列号。下列示例选定当前列并在消息框中显示其列号。
If Selection.Information(wdWithInTable) = True Then
Selection.Columns(1).Select
MsgBox "Column " _
& Selection.Information(wdStartOfRangeColumnNumber)
End If