Word VBA Row/Cell .Height property - ?!?!?!?
Posted on 2003-12-05
Am I like the last loneliest idiot in the world or something? It appears that the Word (2000) VBA Row (or Cell) property .Height doesn't actually return the height of the Row (or Cell).
(assume I've created a single cell table)
will NOT give me the HEIGHT of the FIRST ROW of the FIRST TABLE in the ACTIVE WORD DOCUMENT.
I dunno, I would have said I was pretty specific there...
Instead, the output is dependant on the value of a certain .HeightRule property. There are three possible values:
wdRowHeightAtLeast - Now the row has to be 'At least' .Height tall.
wdRowHeightAuto - The row height is determined by the amount of text therein.
wdRowHeightExactly - The row is exactly .Height tall (.Height is in points)
Here's the really good fun part. When .HeightRule is set to wdRowHeightExactly then .Height is, well, the height of the row. No probs. except we don't know how tall we want it do we, because that rather depends on whetehr the text will fit or not. Ok, next one. When .HeightRule is wdRowHeightAtLeast well now .Height returns the minimum height for the Row. How tall is the row actually? don't ask word, it hasn't got a clue. And finally, wdRowHeightAuto. The row height is determined automatically by the amount of text in it. and what does .Height return? 99999999 - or more specifically wdUndefined. GREAT. THANKYOU MICROSOFT.
So despite the fact that Word MUST know how big that damn Row is - it has to draw and print the damn thing doesn't it? - it WILL NOT tell you how big it is.
OK, I said, it's a little problem, but nothing a good workaround won't solve:
(MyRow as Row, PleaseWork as Long)
MyRow.HeightRule = wdRowHeightAuto
MyRow.Cells(1).Range.Text = "Horses"
MyRow.HeightRule = wdRowHeightExactly
PleaseWork = MyRow.Height
No such luck. Instead, the bit about wdRowHeightExactly actually RESIZED my bloody Row! So that whilst .Height is now accurate, the bottom of the text is chopped off in my Table.
So exactly what the hell is the point in having a .Height property that is readable if you can't actually learn anything from its use? Why not just have a .Height method? hmm? Why not finish the job and have it pop up a little window that says "Screw you programmer! Ha ha! - The boys at MS"
Or maybe it's me. I really hope so. Any ideas anyone? (BTW I'm not just ranting, I really need to sort this out, so beg, grovel etc etc)