PDA

View Full Version : Autofit a Table Width



RayKay
04-04-2020, 01:22 PM
Hi John / everyone

I've tried to make code that narrows all columns in a table to auto fit their text. But it goes one character wide per column.
Any ideas please? So columns will narrow to the width of its contents (unless text is wrapping of course, then that width is fine).
Thus the tables would be narrower in total width. If I change otbl.Parent.Width = 0 to Auto, it still fails. (Parent.Height = 0 works fine for table heights.)



Sub NarrowColumnWidths()


Dim minW As Single
With ActiveWindow.Selection.ShapeRange(1).Table
Set otbl = ActiveWindow.Selection.ShapeRange(1).Table
For iCol = 1 To .Columns.Count
For iRow = 1 To .Rows.Count
With .Cell(iRow, iCol).Shape.TextFrame
otbl.Parent.Width = 0
End With
Next
Next
End With


End Sub


No sure if it's possible, I know you can in Excel and Word, just hoping this may do it?

Thank you.

Aussiebear
04-09-2020, 02:23 AM
Have you tried to do this manually with the macro recorder active?

Paul_Hossler
04-09-2020, 07:42 AM
Have you tried to do this manually with the macro recorder active?


One thing that PP lacks is a macro recorder similar to Excel's and Word's