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 / Tables / August 2004

Tip: Looking for answers? Try searching our database.

Macro to Draw Borders on All Tables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rashid Khan - 23 Aug 2004 17:13 GMT
Hello All,
I am using Office XP and have a document with many tables with variable
number of rows in each table.

I wish to have a macro run on all the Tables in the document and do the
following:
1. Draw an outer border only on all the Tables.
2. Draw a single border above and a double border below on all the Last Rows
of all the Tables.

Can this be achieved through a macro.

TIA
Rashid Khan - 23 Aug 2004 18:58 GMT
Hello All,
further to my previous post.. By Double Border in the last row I meant
Double Underline... I do it manually now by selecting the last row and
pressing Ctrl+Shift+D
> Hello All,
> I am using Office XP and have a document with many tables with variable
[quoted text clipped - 9 lines]
>
> TIA
Chad DeMeyer - 23 Aug 2004 19:31 GMT
Rashid,

The following should do it.

Sub FormatMyTables()
   Dim oTable As Table, oRow As Row i As Long
   For Each oTable In ActiveDocument.Tables
       With oTable
           For i = -4 To -1    'numeric values of wdBorderType constants
               With .Borders(i)
                   .LineStyle = Options.DefaultBorderLineStyle
                   .LineWidth = Options.DefaultBorderLine Width
                   .Color = Options.DefaultBorderColor
               End With
           Next i
           With .Rows(.Rows.Count).Borders(wdBorderTop)
               .LineStyle = Options.DefaultBorderLineStyle
               .LineWidth = Options.DefaultBorderLineWidth
               .Color = Options.DefaultBorderColor
           End With
           .Rows(.Rows.Count).Range.Font.Underline = wdUnderlineDouble
       End With
   Next oTable
End Sub

Regards,
Chad

> Hello All,
> further to my previous post.. By Double Border in the last row I meant
[quoted text clipped - 14 lines]
> >
> > TIA
Rashid Khan - 23 Aug 2004 20:57 GMT
Hi Chad,
Thanks for your reply.  Your macro does not work on my document.. It gives
an error 5991 saying there are vertically merged cells in the table.  I
cannot see with my naked eyes any merged cell.
Is there a way to find merged cells in a Table??
Rashid
> Rashid,
>
[quoted text clipped - 42 lines]
> > >
> > > TIA
Chad DeMeyer - 23 Aug 2004 22:06 GMT
Rashid,

It's usually better to code the Range object than the Selection object, but
cases like this is where I make an exception.  Try replacing this block of
code:

With .Rows(.Rows.Count) ...
...Underline = wdUnderlineDouble

with this block of code:

oTable.Select
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.SelectRow
With Selection.Borders(wdBorderTop)
   .LineStyle = Options.DefaultBorderLineStyle
   .LineWidth = Options.DefaultBorderLineWidth
   .Color = Options.DefaultBorderColor
End With
Selection.Font.Underline = wdUnderlineDouble

Regards,
Chad

> Hi Chad,
> Thanks for your reply.  Your macro does not work on my document.. It gives
[quoted text clipped - 51 lines]
> > > >
> > > > TIA
Rashid Khan - 24 Aug 2004 18:29 GMT
Hi Chad
The macro runs perfectly... but it stopped on one of the table giving Run
Time error 4604...saying "The SelectRow method or property is not available
because some or all of the object does not refer to a table" and highlights
Selection.SelectRow.

Anyhow most of the table are done as I desired... I am just informing u
about the error.  However for your information.. the code I am running on is
on a document which has been OCRed...

Thanks a lot for all the help
Rashid
> Rashid,
>
[quoted text clipped - 77 lines]
> > > > >
> > > > > TIA
 
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.