How to Autofit table row height in powerpoint pptm using VBA?

Viewed 25

I need to adjust row height of some rows in a table on powerpoint (.pptm). This post shows the way for Word VBA. In PPT Rows or Row does not have property "HeightRule".

Can someone help?

1 Answers

This should help you get started:

Sub RowHeight()
    ' This example assumes you've selected the table
    ' PowerPoint won't shrink a row's height past the height of the text in the row
    '   so you'll need to adjust the text height first before shrinking the height.
    ' If you want to increase the height, you can leave out the section of code
    '   below that changes the font size.
    
    Dim oShp As Shape
    Dim oTbl As Table
    Dim lRow As Long
    Dim lCol As Long
    
    Set oShp = ActiveWindow.Selection.ShapeRange(1)
    Set oTbl = oShp.Table
    
    With oTbl
        For lRow = 1 To .Rows.Count
        For lCol = 1 To .Columns.Count
            .Cell(lRow, lCol).Shape.TextFrame2.TextRange.Font.Size = 8
        Next
        Next
        
        For lRow = 1 To .Rows.Count
            .Rows(lRow).Height = 10
        Next
        
    End With
    
End Sub
Related