2010-02-02 75 views

回答

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 
+0

Wowser,這真是太棒了。我現在就測試一下! – Meihua 2010-02-03 00:54:45

+0

剛剛檢查過,這個工程就像一個魅力。好東西!!!! – Meihua 2010-02-03 01:31:11

相關問題