views:

236

answers:

1

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.

+2  A: 

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 
Otaku
Wowser, this is really great. I'll test it out now!
Mahin
Just checked, this works like a charm. Great stuff!!!!
Mahin