代码之家  ›  专栏  ›  技术社区  ›  Meihua

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

  •  4
  • Meihua  · 技术社区  · 15 年前

    有没有一种方法可以通过编程使powerpoint表中的某些列具有相同的宽度?它应该是它们的组合宽度,除以列的数量,但是我想不出一个方法来做这个。

    1 回复  |  直到 14 年前
        1
  •  3
  •   Todd Main    15 年前

    我以前在某个地方回答过这个问题,似乎找不到参考资料。下面是您需要的代码,只需确保您选择了要均匀分布的列

    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