2009-12-17 162 views
2

我正在使用PowerPoint 2000,它沒有2003和更新版本的均勻分佈功能的分佈列。有誰知道什麼VBA代碼將用於均勻分發選定的表格列?我知道如何通過查找表格寬度,除以列數,並將每列的寬度調整爲該分割的寬度來完成整個表格。但是,我有問題只適用於例如右列7列中的5列)Powerpoint VBA - 均勻分佈列

回答

1

獲取要嘗試分發的列的寬度總和,然後除以列數。

2

這將爲你做的伎倆。只需確保在運行時選擇了列。

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