Columns 集合对象

         
Table
Columns (Column)
CellRange (Cell)

Column 对象的集合,代表表格中的列。

使用 Columns 集合

使用 Columns 属性可返回 Columns 集合。本示例查找当前演示文稿中的第一个表格,并计算 Columns 集合中的 Column 对象数,然后向用户显示信息。

Dim ColCount, sl, sh As Integer

With ActivePresentation
    For sl = 1 To .Slides.Count
        For sh = 1 To .Slides(sl).Shapes.Count
            If .Slides(sl).Shapes(sh).HasTable Then
                ColCount = .Slides(sl).Shapes(sh) _
                    .Table.Columns.Count
                MsgBox "Shape " & sh & " on slide " & sl & _
                    " contains the first table and has " & _
                    ColCount & " columns."
                Exit Sub
            End If
        Next
    Next
End With

使用 Add 方法可向表格中添加一列。本示例在现有表格中创建一列,然后将新列的宽度设置为 72 磅(1 英寸)。

With ActivePresentation.Slides(2).Shapes(5).Table
    .Columns.Add.Width = 72
End With

使用 Columns(index) 可返回一个 Column 对象。Index 代表 Columns 集合中列的位置(通常是从左向右计算的;但 TableDirection 属性可变换计算方向)。本示例选择第二张幻灯片第五个形状的表格中的第一列。

ActivePresentation.Slides(2).Shapes(5).Table.Columns(1).Select