A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Macro to Draw Borders on All Tables



 
 
Thread Tools Display Modes
  #1  
Old August 23rd, 2004, 05:13 PM
Rashid Khan
external usenet poster
 
Posts: n/a
Default Macro to Draw Borders on All Tables

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


  #2  
Old August 23rd, 2004, 06:58 PM
Rashid Khan
external usenet poster
 
Posts: n/a
Default

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
"Rashid Khan" wrote in message
...
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




  #3  
Old August 23rd, 2004, 07:31 PM
Chad DeMeyer
external usenet poster
 
Posts: n/a
Default

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


"Rashid Khan" wrote in message
...
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
"Rashid Khan" wrote in message
...
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






  #4  
Old August 23rd, 2004, 08:57 PM
Rashid Khan
external usenet poster
 
Posts: n/a
Default

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
"Chad DeMeyer" cjdemeye at bechtel dot com wrote in message
...
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


"Rashid Khan" wrote in message
...
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
"Rashid Khan" wrote in message
...
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








  #5  
Old August 23rd, 2004, 10:06 PM
Chad DeMeyer
external usenet poster
 
Posts: n/a
Default

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


"Rashid Khan" wrote in message
...
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
"Chad DeMeyer" cjdemeye at bechtel dot com wrote in message
...
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


"Rashid Khan" wrote in message
...
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
"Rashid Khan" wrote in message
...
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










  #6  
Old August 24th, 2004, 06:29 PM
Rashid Khan
external usenet poster
 
Posts: n/a
Default

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
"Chad DeMeyer" cjdemeye at bechtel dot com wrote in message
...
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


"Rashid Khan" wrote in message
...
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
"Chad DeMeyer" cjdemeye at bechtel dot com wrote in message
...
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


"Rashid Khan" wrote in message
...
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
"Rashid Khan" wrote in message
...
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












 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down Object Selection in Macro Herman Merman Worksheet Functions 3 August 16th, 2004 06:18 AM
Print Macro Terry General Discussions 1 June 23rd, 2004 09:04 AM
Macro command go to last filled cell in column? PatsyB. Setting up and Configuration 1 May 17th, 2004 08:09 PM
word error mac General Discussions 1 May 6th, 2004 08:14 AM
Macro buttons ...help please ttd Worksheet Functions 1 March 26th, 2004 08:47 PM


All times are GMT +1. The time now is 09:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.