Detect if table extends beyond right border?

R

rVo

Hi all,

Is there a possibility to find out if the content of a page extends beyond
the right margin?
I'm asking this because I'm inserting content from some documents into one
large document. I have no control over the content of the source documents.
Somethimes parts of these documents set in Landscape mode, I wrote a routine
to detect this, but for some odd reason it seems to fail every now and then.
I thought it would be good to check in the result document if there are any
landscape pages that are set to portrait with content that requires
landscape.

Typically this problem occurs with tables, so I should be able to find out
if the right border of a table is positioned to far to the right, but I
couldn't find any property like that for a table. I could add the width of
all cells on a row, but this doesn't seem to work if you have joined cells
in your tables and - as mentioned before - I have no real control over the
input, so joined cells are possible (and have occured allready).

Is it possible to find out that one is positioned in the last cell of a row?
Maybe it is possible to select the cell's content and ask for the
right-value of the selection then?

Any other solution would be more than welcome.

Kind regards,

rVo
 
J

Jezebel

You can check if you are in the last cell of a row by looking at the next
cell (ie the cell's Next property) -- if that's empty you're in the last
cell of the table. If not, and the next cell's RowIndex is greater, then
you're at the end of the row. If the table is uniform, you need check only
the first row.

Having found the last cell in the row, use the Information() function to get
your horizontal position: horizontal position of the start of the cell, plus
the width of the cell, should tell you what you need to know --

Dim pTable as Word.Table
Dim pCell as Word.Cell
Dim pTableWidth as double
Dim pRightEdge as double

For each pTable in ActiveDocument.Tables
pTableWidth = 0
Set pCell = pTable.Cells(1,1)
do
pRightEdge =
pCell.Range.Information(wdHorizontalPositionRelativeToPage) + pCell.Width
if pRightEdge > pTableWidth then
pTableWidth = pRightEdge
End if

set pCell = pCell.Next
if ptable.Uniform and pCell.RowIndex > 1 then
exit do
End if

Loop until pCell is nothing

if pTableWidth > THRESHHOLD then
pTable.Select
MsgBox "Too wide"
exit for
end if

Next
 
R

rVo

Thanks Jezebel,

This works fine as long as there aren't any "joined" cells. In that case an
error message appears.

I've come up with a pretty dirty solution, but this one has not caused any
errors upto now.
I select the entire table and move one char to the right (move, not extend)
then one char back tot the left.
Then I'm positioned directly behind the table (to the right that is). From
this point I can ask the posintion info and fix any page orientation errors.
I think the implementation of tablehandling in VBA is a small disaster
though.

Kind regards,

rVo
 
R

rVo

Something like "The property is not available on this table as it contains
joined cells" (I use a Dutch version of Word, so I translated the message
for you).
 
J

Jezebel

You won't get that error if you iterate the cells themselves, as suggested.
That error comes up if you try to work with rows or columns in a non-uniform
table.
 

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