Tables formatting macro

B

buncs

I need to make a user's tables have a standard look. He gets tables from a number of other users and they all look different

Does anybody know of a macro that formats any table regardless of number of columns, so that they all have the same width and look - that is, it needs to adjust each column width in proportion to the change in width of the table. Also needs to make the border styles the same.

The user could apply the macro to tables individually. In that way he could back out if for some reason the table was too complex for the macro.

My VB is too limited to do this. I'd be willing to pay someone to do it if there was nothing available.
 
P

Peter Hewett

Hi

Try this, I've put it together very quickly so I may have overlooked
something but it should be a good starting point:

Public Sub ProportionallyResizeTable(ByVal tblToResize As Word.Table)
Dim rowObj As Word.Row
Dim celItem As Word.Cell
Dim sngRowWidth As Single
Dim sngPageWidth As Single
Dim sngScale As Single

' Get the usable page width
With tblToResize.Range.PageSetup
sngPageWidth = .PageWidth - .LeftMargin - .RightMargin
End With

' Calculate Row width
For Each rowObj In tblToResize.Rows

' Calculate Row width
sngRowWidth = 0
For Each celItem In rowObj.Cells
sngRowWidth = sngRowWidth + celItem.Width
Next

' Calculate scaling factor
sngScale = sngPageWidth / sngRowWidth

' Resize each Cell in the Row
For Each celItem In rowObj.Cells
celItem.Width = celItem.Width * sngScale
Next
Next
End Sub

It currently does not deal with nested tables, but I wrote it as a
procedure so that you can easily modify it to make it recursive.

To use it call it something like:

ProportionallyResizeTable ActiveDocument.Tables(1)

It resizes a table to utilise the maximum available page width. However, if
the left edge of the table is outside the left border it does not adjust
for this or take it into accout (I said it was simple!)

HTH + Cheers = Peter
 

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