Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining table size relative to page size and formatting

Status
Not open for further replies.

VicTags

IS-IT--Management
May 6, 2002
4
0
0
US
I've searched pretty exensively through the forum for a solution to this but I don't think it's been covered.

I have an extremely large (> 1000 page) word document with a combination of text, graphics and tables.

The document itself is an export from a requirements tracking database and is very poorly formatted.

In addition to various other formatting I need to reformat any table which is bigger than a page in any direction. I can't post the code because it's on a separate computer but currently. I just look for tables with > 40 rows and then count the characters per row convert the font to points and compare it to the page size to determine if it runs over horizontally. This process alone is extremely slow.

The formatting correction required for these tables is to line up the columns and reduce the font size until the table fits. It can be reasonably assumed that the table will fit with > 6 point font if formatted correctly.

So far I have had some luck with this algorithm:
- count the cells in each row
- divide the page size by the number of cells per row
- make each cell in the row equal to that size
- repeat for all rows
- set the table auto-format to "fit to window"

This gets the job done but as you can imagine on a > 40 row table it takes forever. There are at least 30 of these tables in a document.

My question is two fold. Is there any way to directly measure the size of a table relative to a page? ActiveDocument.Tables(x).preferredWidth doesn't do it. It's just 100 whether it's over or not. The second question, is there any quicker way to perform the task I outlined above?

Thanks,

Victor

 
So far I have had some luck with this algorithm:
- count the cells in each row
- divide the page size by the number of cells per row
- make each cell in the row equal to that size
- repeat for all rows

Aaaiiiii!

OK. Ummm, gotta ask. Why are you repeating for each row? PLEASE do not tell me that you have merged cells, and uneven number of cells/row.
Code:
Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
will bring in any table extended outside the page horizontally.

Then, possibly, change the font size, and:
Code:
Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)

You could run through all the tables by using a table object:
Code:
Dim aTable As Table
For Each aTable In ActiveDocument.Tables
  aTable.AutoFitBehavior (wdAutoFitWindow)
' font resize????
  aTable.AutoFitBehavior (wdAutoFitContent)

Hard to say without a bit more detail.

Are you serious that each table has to fit on ONE page? No going over?

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top