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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |