title: Auto resize cells within table
body: <p>How do I auto resize the column width or row height in a PowerPoint table?</p>
  
  <p>Edit: I am working with PowerPoint 2010 and I wanted something like:</p>
  
  <pre><code>Sub table_fix()
   Dim icol As Integer, irow As Integer, minW As Single, minH As Single
   With ActiveWindow.Selection.ShapeRange(1).table
    For icol = 1 To .Columns.Count
     For irow = 1 To .Rows.Count
      With .Cell(irow, icol).Shape.TextFrame
       If minW = 0 Then minW = .TextRange.BoundWidth + .MarginLeft + .MarginRight
       If minW &lt; .TextRange.BoundWidth + .MarginLeft + .MarginRight Then minW = .TextRange.BoundWidth + .MarginLeft + .MarginRight
      End With
     Next
     .Columns(icol).Width = minW
    Next
   End With
   With ActiveWindow.Selection.ShapeRange(1).table
    For irow = 1 To .Rows.Count
     For icol = 1 To .Columns.Count
      With .Cell(irow, icol).Shape.TextFrame
       If minH = 0 Then minH = .TextRange.BoundHeight + .MarginTop + .MarginBottom
       If minH &lt; .TextRange.BoundHeight + .MarginTop + .MarginBottom Then minH = .TextRange.BoundHeight + .MarginTop + .MarginBottom
      End With
     Next
     .Rows(irow).Height = minH
    Next
   End With
  End Sub
  </code></pre>
  
  <p>This code does not fix all column widths and all row heights. It has some mess ups on which columns to resize when the columns are narrow and high and it adds random spaces on some numbers sometimes.</p>
  
  <p>I was hoping I could simulate "resizing of a cell through double clicking on the border". I believe I need to have some kind of iteration calculation with <code>BoundWidth</code> and <code>BoundHeight</code> or does 2010 have my originally searched for feature?</p>
  
  <p>Edit 2: I have split the code for testing:</p>
  
  <pre><code>Sub IT()
   Dim icol As Integer, irow As Integer, minW As Single, minH As Single
   Call max_it
   Call size_it
  End Sub
  
  Function max_it()
   With ActiveWindow.Selection.ShapeRange(1).table
    For icol = 1 To .Columns.Count
     .Columns(icol).Width = 1000
    Next
   End With
  End Function
  
  Function size_it()
   With ActiveWindow.Selection.ShapeRange(1).table
    For icol = 1 To .Columns.Count
     For irow = 1 To .Rows.Count
      With .Cell(irow, icol).Shape.TextFrame
       If minW = 0 Then minW = .TextRange.BoundWidth + .MarginLeft + .MarginRight
       If minW &lt; .TextRange.BoundWidth + .MarginLeft + .MarginRight Then minW = .TextRange.BoundWidth + .MarginLeft + .MarginRight
      End With
     Next
     .Columns(icol).Width = minW
     minW = 0
     If icol &lt; .Columns.Count Then .Columns(icol + 1).Width = 1000
    Next
    For irow = 1 To .Rows.Count
     For icol = 1 To .Columns.Count
      With .Cell(irow, icol).Shape.TextFrame
       If minH = 0 Then minH = .TextRange.BoundHeight + .MarginTop + .MarginBottom
       If minH &lt; .TextRange.BoundHeight + .MarginTop + .MarginBottom Then minH = .TextRange.BoundHeight + .MarginTop + .MarginBottom
      End With
     Next
     .Rows(irow).Height = minH
    Next
   End With
  End Function
  </code></pre>
  
  <p>When I run <code>max_it</code> and <code>size_it</code> separately, it does what I want, but if I call IT to run the two functions after each other it ignores the <code>max_it</code> part and therefore the <code>size_it</code> will not return the correct <code>BoundWidth</code> if the cells are "narrow and high".</p>
  
  <p>I may have some beginner's mistake, like: VBA is smart and realizes that the first max_it changes will be redone by <code>size_it</code> and therefore ignores the code (?)</p>