How to find programmatically Word table row height?

E

Erez Harari

I write Word VBA script that contains the following code:

For Each R In Tbl.rows
If R.Height <= 100 Then
.......
End If
Next

The property R.Height returns 9999999 when R.HeightRule = wdRowHeightAuto and
12 when R.HeightRule = wdRowHeightExactly In both cases the row height is
wrong.
Why the property R.Height returns wrong values?
Is there is a way to find programmatically the row height?

Thanks in advance
 
H

Helmut Weber

Hi Erez,

mostly, if not always, Word's answer to a question is "9999999",
if there would be more than one answer,
or if the answer would be "undefined".

Not perfectly suitably here, though, as at the moment
of asking, if the cells don't have different height,
there would be a unique answer.

What values do you get?

Here and now, if I set the height of a row to 12 pt,
MsgBox ...Height returns 12.

If you set the height in inches or centimeters,
there may be problems concerning fractions.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
E

Erez Harari

Helmut Weber,
Hi,

The problem is that the Height property of the table rows returns always the
same incorrect value (whatever units it means), I know that the values is
incorrect, because some rows are about 1 centimeter and other rows are about
20 centimeters height. Each row consists on same number of cells of the same
height and the Height property of the cells returns the same wrong value
(9999999 or 12) as the row's Height property.
I don't have to change the row's height. I only have to find what it is.

Erez Harari
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RXJleiBIYXJhcmk=?=,
I write Word VBA script that contains the following code:

For Each R In Tbl.rows
If R.Height <= 100 Then
.......
End If
Next

The property R.Height returns 9999999 when R.HeightRule = wdRowHeightAuto and
12 when R.HeightRule = wdRowHeightExactly In both cases the row height is
wrong.
Why the property R.Height returns wrong values?
Is there is a way to find programmatically the row height?
If the row height is set to Auto, then 999999 is the correct return value. When
you query the height of a row, you're not querying the display on the page,
you're querying the .Height setting.

What do you expect the return value to be instead of 12 for wdRowHeightExactly?
The returned value should be in points (not inches or centimeters or pixels).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
E

Erez Harari

Cindy Meister
Hi,

I want to know how many pixels every row takes on screen.

Erez Harari
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RXJleiBIYXJhcmk=?=,
I want to know how many pixels every row takes on screen.
The Word object model has a PointsToPixels method you can
use to convert the value you're getting back to Pixels.
(But only when the row height is set to an "exact" value!)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
E

Erez Harari

Cindy Meister
Hi,

I want to know the height every row takes on screen.

Remarks:
1) I create the table using ConvertToTable function and never set rows or
cells Height property.
2) I don't care about units, the only thing that matter is how to find the
row height.
3) The row Height return the right value only after I set it, but this make
no sense, since I don't know witch value the row height should be. I need to
find the row height without change it.
4) I need to know the rows height, because in my program I set the rows
property AllowBreakAcrossPages to false, this cause a problem in rows that
are too heigh to feet in one page, in that case Word cut of the overflow
text. I try to use row height to verify that the row feet to one page before
I change the AllowBreakAcrossPages property.
Is there is another solution to that problem without using row Height
property?

Erez Harari
 
C

Cindy M -WordMVP-

Hi Erez,

No, there's not really any good way for you to determine what you need.
Possibly, the .Information property of the Range/Selection objects can help
you. There are a couple of arguments for this that give you the position
on-screen; and a couple more that return the page numbers.

I do notice the following, which may help you to a solution

1. I have a table cell where the row is not allowed to break across pages. It
contains too much text, so the text is disappearing at the bottom

2. When I check ?Selection.Information(wdVerticalPositionRelativeToPage) with
the cursor at the last visible line, then again further down, I do get
different values.
I want to know the height every row takes on screen.

Remarks:
1) I create the table using ConvertToTable function and never set rows or
cells Height property.
2) I don't care about units, the only thing that matter is how to find the
row height.
3) The row Height return the right value only after I set it, but this make
no sense, since I don't know witch value the row height should be. I need to
find the row height without change it.
4) I need to know the rows height, because in my program I set the rows
property AllowBreakAcrossPages to false, this cause a problem in rows that
are too heigh to feet in one page, in that case Word cut of the overflow
text. I try to use row height to verify that the row feet to one page before
I change the AllowBreakAcrossPages property.
Is there is another solution to that problem without using row Height
property?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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