Presentation Magazine Forum > PowerPoint Questions and Answers

Resize-to-fit Table Columns (PowerPoint)

 
06-06-10
icu222much
 
Posts: 1
Resize-to-fit Table Columns (PowerPoint)

I have a table in PowerPoint with several rows and columns of data. I would like to resize selected columns so the width of the column does not exceed the width of the longest data - in otherwords make the column width the perfect fit. I am wondering how I would go abouts in doing this?

Below are my various attempts but they have failed as when I went to run my macro, the column widths did not change.

[code]mySlide.Shapes(mySlide.Shapes.Count).Table.Cell(x, y).Shape.TextFrame.WordWrap = msoFalse
mySlide.Shapes(mySlide.Shapes.Count).Table.Cell(x, y).Shape.TextFrame.AutoSize = ppAutoSizeShapeToFitText[/code]

[code]mySlide.Shapes(mySlide.Shapes.Count).Table.Columns (x).Width = ppAutoSizeShapeToFitText[/code]

[code]mySlide.Shapes(mySlide.Shapes.Count).Table.Cell(ta rgetRow, targetColumn).Shape.TextFrame.AutoSize = ppAutoSizeShapeToFitText[/code]


 
22-07-10
ori_pira
 
Posts: 2
My solution!

Not sure if this thread is still active?

I had much the same challenge as icu222much - wanting to use vba to automate the resizing of tables to match cell contents. My solution was to create (programmatically) a text box, put the text of the cell into the text box (together with font size and font name), resize the text box, get width and height of the text box, and use these values to set width and height of the cell in the table. Once all the cells are done, the text box is deleted.

Had thought of posting the code here, but it exceeds the limit on number of characters Is there a way to post vba code to this forum?


 
22-07-10
John Wilson
 
Posts: 296

Sub table_fix()
Dim icol As Integer, irow As Integer, minW 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 + 1
If minW < .TextRange.BoundWidth + .MarginLeft + .MarginRight + 1 Then _
minW = .TextRange.BoundWidth + .MarginLeft + .MarginRight + 1
End With
Next
.Columns(icol).Width = minW
Next
End With
End Sub
__________________
John Wilson
Microsoft PowerPoint MVP
PowerPoint Alchemy


 
29-07-10
ori_pira
 
Posts: 2
Cool Properties

Hello John,

I spent ages trying to find a property/method of the "autofit" type for table cells in powerpoint vba. Good to know that there is one. Quite a long way down the chain from the table cell object. I see there is also a boundheight property, for autosizing rows.

To the moderators: is there a way to make submitted vba code more legible, (preferrably with the same appearance as in the VB editor)?


 
02-08-10
John Wilson
 
Posts: 296

BoundHeight and BoundWidth are properties of the textrange and don't just apply to tables btw
__________________
John Wilson
Microsoft PowerPoint MVP
PowerPoint Alchemy




Similar Threads
Thread Thread Starter Forum Replies
Generating a table of contents for printed version of Powerpoint presentation jules_trini PowerPoint Questions and Answers 4
Powerpoint with video from Mac to PC lobopaco PowerPoint Questions and Answers 2