if autosize is done to tables rows, correct height is not retuned

M

madhu

hi,

Selection.Tables(1).Cell(1, 1).Height=10
Selection.Tables(1).Rows.HeightRule = wdRowHeightAuto
MsgBox Selection.Tables(1).Cell(1, 1).Height

what I am getting is "9999999" instead of getting actual height of row
is this a bug?
I am using word2000
 
J

Jay Freedman

It isn't a bug, although most VBA developers would consider it an extremely
unfortunate "feature".

The value 9999999 is the value of the built-in constant wdUndefined, which
Word returns for all sorts of "auto" settings as well as for measurements on
ranges that contain mixed values (for example, Selection.Font.Size when the
selection contains two or more font sizes).

Setting the HeightRule to wdRowHeightAuto is equivalent to going into Table
Table Properties > Row and clearing the Specify Height check box. Notice
how the height measurement becomes grayed out -- that's "undefined".

There isn't any really good way to find the height of an auto-height row. A
horrible kludge is to get the .Information(wdVerticalPositionRelativeToPage)
value of the first character of the first cell in the row, get the same
value for the first character of the first cell of the next row, and take
the difference. You also have to deal with the possibility that there is no
next row, or that the rows are on different pages. It's just plain ugly.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
B

Bear

And if you could make do with knowing how many lines are in a cell, you could
use:

Set objRange = objRow.Cells(C).Range
objRange.End = objRange.End - 1
intRowLines = objRange.ComputeStatistics(wdStatisticLines)

Bear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top