开发者

How To Make Selected Columns the Same Width in a PowerPoint Table?

Is there a way开发者_高级运维 to programmatically make only some columns in a PowerPoint table the same width? It should be their combinded width, divided by the number of columns, but I can't figure out a way to do this.


I've answered this before somewhere, couldn't seem to find that reference. Here's the code you'll need, just make sure you have the columns selected that you want to be distributed evenly

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜