Reputation: 63
Using MS Word VBA. I already have a nice macro that autofits all table widths to the window size (margin to margin).
I'm looking to do something similar to autofit all of the table row heights to display all of the text in each row. Currently, the table rows only display one line, and then the text wraps below and is not visible.
Any help is appreciated. Code is below:
Sub ResizeAllTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
oTbl.AutoFitBehavior wdAutoFitWindow
Next oTbl
End Sub
Upvotes: 3
Views: 3604
Reputation: 2145
You are looking for the Row.HeightRule property. Specifically, you will want it to be set to wdRowHeightAuto which is
The row height is adjusted to accommodate the tallest value in the row.
So using your example I would imagine it would look something like this
Sub ResizeAllTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
oTbl.Rows.HeightRule = wdRowHeightAuto
Next oTbl
End Sub
Upvotes: 3