How to find the bottom of a table in VBA

S

scottw

From template code I need to place images along the right side of my reports,
with text on the left.

I currently use a table positioned to the right margin for placing these
images. I then fill other tables positioned on the left margin with text.
All the tables are of varied length, filled from text read from files.

I would like to widen the rows in the text tables once they safetly pass the
bottom of the image table, but am finding it very difficult to get the needed
information from the 'Range.information' object.

If anyone has any solutions for this it would be greatly appreciated.

Thank you in advance.

Additional info-
Version: word 2003
Have tried placing a 'right justified' bookmark under each table in the
hopes of finding out it's wdVerticalPositionrelativePage, but this
consistantly gives the right margin (even when I see the bookmark is actually
3 inches to the left!) It seems word is measuring from an assumption that my
bookmark is right justified so it must be on the margin.)
 
T

Tony Jollans

Hi scottw,

Is there a reason you're using tables for your text? Word will happily wrap
text around pictures without you making a complex table.

Apart from that I don't understand what you mean when you say the *vertical*
position gives you the right margin - a horizontal measurement.
 
S

scottw

To stat, thank you for your time Tony,

As to why the tables, it is because there are many templates in place and
they have the text tables already, each with potentially varied fonts and
formats, so they are not avoidable.

For the vertical position - yes - my bad, I do mean horizontal. This is
what I intended to do:

I noticed that if I selected the line of text just below my text table and
right justifying that line, it would automatically be positioned just to the
left of my image table. Since the desired width of my next text row is also
just to the left of my image table, I thought I could get the
'wdHorizontalPositionRelativeToPage' and use it to set the width of my next
row. However the number I get back is always the same (my right margin)
whether I have an image table or not on the right.

Initially I though I would make a 'map' from the bottoms and widths of the
image tables and contour my text rows to that map, but finding the bottoms
of the tables has also eluded me.

I will attempt to show the layout, I hope the spacing translates!
| | |
|
| | | IMAGE TABLE ONE |
| | | (WIDE)
|
| | ---------------------------------------------- |
| | --> --> |
|
| TEXT TABLE | WANT TO --> | IMAGE TABLE |
| | WIDEN ROW --> | TWO |
| | TO USE THIS SPACE | |
----------------------- |
|
(NEXT LINE) (RIGHT JUSTIFIED CUSOR) ^ | |

Thanks again
 
J

Jezebel

For a different approach to this, have a look at the
ActiveWindow.ActivePane.Pages(n).Rectangles collection. You'll be something
of a pioneer if you can work with this, because the documentation is cursory
to say the least and I've seen almost no references to it in postings here
(and it's a recent addition to Word VBA). But it's a part of the Word object
model that appears to be intended for your sort of purpose - ie, working
with the things on the page specifically as graphic elements.
 
T

Tony Jollans

You are attempting something rather difficult but, more importantly, you are
trying to outdo Word. I suspect that you will come to grief sooner or later
with this and really would encourage you to find an alternative method.

If you have to use the text tables, what about the images? Couldn't they be
placed inside the text table so that text could flow round them within the
table cells - or do the images really need to line up with each other rather
than any related text?

--
Enjoy,
Tony

scottw said:
To stat, thank you for your time Tony,

As to why the tables, it is because there are many templates in place and
they have the text tables already, each with potentially varied fonts and
formats, so they are not avoidable.

For the vertical position - yes - my bad, I do mean horizontal. This is
what I intended to do:

I noticed that if I selected the line of text just below my text table and
right justifying that line, it would automatically be positioned just to the
left of my image table. Since the desired width of my next text row is also
just to the left of my image table, I thought I could get the
'wdHorizontalPositionRelativeToPage' and use it to set the width of my next
row. However the number I get back is always the same (my right margin)
whether I have an image table or not on the right.

Initially I though I would make a 'map' from the bottoms and widths of the
image tables and contour my text rows to that map, but finding the bottoms
of the tables has also eluded me.

I will attempt to show the layout, I hope the spacing translates!
| | |
|
| | | IMAGE TABLE ONE |
| | | (WIDE)
|
|
| ---------------------------------------------- |
 
S

scottw

Thank you Tony (and Jezebel) for the help.

The problem that limits me is not knowing the size in advance for any of
these tables, so putting an image in one of them would only solve the problem
if the image was just right for that table.

I'm convinced that you are right about the difficulty of this, still
looking for the alternative method though. The users of these reports are
very picky about style things like font type, size and color and the styles
vary greatly, even from table to table (and cell to cell) within one report.
Having the tables also gives non tech users an interface for laying out
those styles, etc.

The only way I could imagine to replace these tables would be having VB read
each table's style properties then remove the table and type the contents
back. But, since hundreds of these templates already exist, and contents
come from a mix of code and the tables themselves - this code would need to
be able to read the code modules of these templates at the same time!

It seems so much more reasonable to have a function that would simply add
rows whos widths were based on the left edge of the pre-placed image tables
to the right. I could then simply replace any code that puts text into a
cell with a call to this function, and the function would minimize the
area between the text row ends and the images.

If only that right justified cursor could tell me its real vertical
position! That way I could know exactly what the right edge of my text area.
Instead it tells me the right margin of the page.

Thanks for the efforts,

Scott
 
S

scottw

Hi Jezebel and thanks for the input. I took a look at the pane object model,
but could not find a way to get it to report what I needed. If you happen
to come accross a way for it (or any other object) to return the exact
position (as opposed to the position of the right page margin) of a right
justified cusor, that would solve my problem. Do you know if the panes
collection has a 'rectangle ' (or anything) that contains the paragraphs
between the images?
Thanks again,
Scott
 
T

Tony Jollans

Caveat: This is based on trial and error to a certain extent.

I'm not sure enough of your layout to take this further but see if this is
any help. It will pop a message box with the coordinates of the bottom left
corner of a table (in points from the top left of the page).

Set T = ActiveDocument.Tables(2) ' Your table here
Set C = T.Range.Cells(T.Range.Cells.Count).Range
P = C.Information(wdActiveEndPageNumber)

For Each R In ActiveWindow.ActivePane.Pages(P).Rectangles
If R.RectangleType = wdTextRectangle Then
If R.Range.Start <= C.Start And R.Range.End >= C.End Then
Exit For
End If
End If
Next

MsgBox "Bottom of Table is at " & vbTab & R.Top + R.Height & vbCr & _
" Left of Table is at " & vbTab & R.Left
 
S

scottw

Sterling work Tony, as was (I am painfully learning) your earlier
assessment that mentions 'rather difficult' and 'grief'!

Thank you very much.
Scott W.
 

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