I have a seven-page table in Word created by VBA code. (See the attached, 1-page excerpt.) After I create the table, the rows can have widely varying heights. I’d like to add code that would make the rows preferred height be the same for all cells that have just one line but, if necessary, I’d like the height to expand if a cell has two rows.
I’m currently using the following five lines of code, downloaded from some site on the Internet, to adjust the height of the table:
Dim tr As Row
For Each tr In ActiveDocument.Tables(1).Rows
'HeightRule is an enumeration with three values. By specifying
'wdRowHeightExactly for the value, we are forcing an exact height for table
' You can also specify wdRowHeightAuto (the default, row height is adjusted to
'accomodate the tallest value in the row) or wdRowHeightAtLeast (specify a
'minimum value. This option is selected if you manually adjust the height of
tr.HeightRule = wdRowHeightExactly
'Note that row height is in points, not inches (the Table Tools Layout tab in the UI
'uses inches. There are 72 points per inch.)
tr.Height = 13
That code cuts off the bottom of the title bar in the attached table and also does not allow expansion of height when necessary. To show that, I copied and pasted the first French word in the list a few extra times in the cell to see if the table could adjust itself when a cell had two lines. The table does not adjust to fit the line, but you can force an expansion manually, and you will then see there is more text in the cell in the second row (line numbered 1) than first displayed.
If I use the wdRowHeightAuto argument, that does not pull the table height down to something reasonable. The table before I run the code has a consistent row height of about five lines of text, even though very few lines have more than one line of text. It appears that wdRowHeightAuto is useless without some further help.
Is there some VBA code that can set a standard, preferred height for rows in a table? If not, I can still use the above code and then adjust rows by hand after I make the table.
The table is also giving problems in some subsequent pages in that the bottom of the last line of the table at the bottom of a page is sometimes getting cut off in the middle of a row. For space reasons, I did not include a table that shows that problem, but I think a solution to my original problem will fix that second problem.
Thanks, as always, for help. Whenever I find an impossible problem, someone in EE usually solves the impossible problem.
Jra in Priddis, Alberta