Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2004

Tip: Looking for answers? Try searching our database.

Tables formatting macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
buncs - 31 Jan 2004 03:41 GMT
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.
Peter Hewett - 31 Jan 2004 04:34 GMT
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

"=?Utf-8?B?YnVuY3M=?=" <tikouka@ihug.co.nz> wrote in
news:CFBE63D7-1B35-4D4E-A841-37A6064A9A1F@microsoft.com:

> 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.
[quoted text clipped - 10 lines]
> My VB is too limited to do this.  I'd be willing to pay someone to do it
> if there was nothing available.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.