[Word VBA] how to compute a table occupies rows number

jackni

Board Regular
Joined
Feb 10, 2011
Messages
73
Hi, All

In WORD, when a table's column width is not large enough, usually some cells will occupies more than one row to display content in it.
For example:
A 3 * 4 table, when content in each cell is not long enough, the table occupy only 3 rows in WORD, but when content in for exam. "cell(2,1)" is very long, the table will occupy more than 3 rows.
How do I compute lines a table occupies?
I know one way to check each cell's range, and use computestatistics(wdstatisticslines), but it has to check each cell's range, there are a lot of tables in word,i t's not a time-saving method.
Is there a better way than this? maybe row by row, or just can compute table's lines.
Thank you very much!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
What you are trying to do is not easy in Word. but here is another siggestion
(place bookmark at foot of table)
You could calcualte vertical positions of various things and use difference to get height
(bookmark vertical position - top of table is approx table height etc)

Code:
    Set tbl = ActiveDocument.Tables(1)
'TOP of TABLE
    tbl.Select
    MsgBox 1 & vbTab & Selection.Information(wdVerticalPositionRelativeToPage)
'TOP OF EACH ROW IN TABLE
    For r = 1 To tbl.Rows.Count
        tbl.Cell(r, 1).Select
        MsgBox "row " & r & vbTab & Selection.Information(wdVerticalPositionRelativeToPage)
    Next r
'BOOKMARK placed at foot of table
    MsgBox 3 & vbTab & ActiveDocument.Bookmarks("NameOfBookmark").Range.Information(wdVerticalPositionRelativeToPage)
 
Last edited:
Upvote 0
Yongle,
Thank you very much, your idea is great, I think I'll take your advise!
Thanks again!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top