如何使选定的列在PowerPoint表中具有相同的宽度?

时间:2010-02-02 21:18:40

标签: vba powerpoint powerpoint-vba

有没有办法以编程方式只使PowerPoint表中的某些列具有相同的宽度?它应该是它们的组合宽度除以列数,但我无法想办法做到这一点。

1 个答案:

答案 0 :(得分:3)

我在某个地方之前已经回答过,似乎无法找到那个参考。这是您需要的代码,只需确保选择了要均匀分布的列

Sub DistributeSelectedColumnsEvenly() 
Dim sel As Selection 
Set sel = ActiveWindow.Selection 
Dim fColumn As Integer 
fColumn = 0 
Dim lColumn As Integer 
Dim columnsWidth As Integer 

With sel 
    If .Type = ppSelectionShapes Then 
        If .ShapeRange.Type = msoTable Then 
            Dim tbl As Table 
            Set tbl = .ShapeRange.Table 
            Dim tblColumnCount As Integer 
            tblColumnCount = tbl.Columns.Count 
            For colNum = 1 To tblColumnCount 
                If tbl.Cell(1, colNum).Selected Then 
                columnsWidth = columnsWidth + tbl.Cell(1, colNum).Parent.Columns(colNum).Width 
                    If fColumn = 0 Then 
                        fColumn = colNum 
                    End If 
                    lColumn = colNum 
                End If 
            Next 
            Dim columnCount As Integer 
            columnCount = (lColumn - fColumn) + 1 
            Dim columnWidth As Integer 
            columnWidth = columnsWidth / columnCount 
            For columnIndex = fColumn To lColumn 
                tbl.Columns(columnIndex).Width = columnWidth 
            Next 
        End If 
    End If 
End With 
End Sub