border on last row on multi-page tables

S

synnamone

Does anyone out there know if there's a way to automagically have Word apply a bottom border to the last row on each page of a table that spans multiple pages (Note: There are no internal horizontal lines in the format we're using)??? Short of going to the the last row on each page and putting it in manually; I can't figure it out. HELP!!!
 
P

Peter Hewett

Hi =?Utf-8?B?c3lubmFtb25l?= (Isn't anonymity a wonderful thing!)

Word can't do what you want automatically. You can't do EXACTLY what you
want at all, as the lines you create are actually table cell borders. So
the bottom of one rows cells are the top of the next - even if the next
rows on the next page. I hope that makes sense if not create a document
with a table that spans two pages and manually format the last row of the
table on the first page and you'll see what I mean.

If this compromise is acceptable, here's some code that may help:


Public Sub TableLines()
Dim tblTemp As Word.Table
Dim rowItem As Word.Row
Dim lngBasePageNo As Long
Dim lngCurrentPageNo As Long
Dim lngRowIndex As Long

' Do this for ALL tables in the document
For Each tblTemp In ActiveDocument.Tables

' Get the page number of the first row so
' that we establish a reference point
lngBasePageNo = _
tblTemp.Rows(1).Range.Information(wdActiveEndPageNumber)

' Loop through ALL rows in the table
For lngRowIndex = 1 To tblTemp.Rows.Count

Set rowItem = tblTemp.Rows(lngRowIndex)

' Page number of the current row
lngCurrentPageNo = _
rowItem.Range.Information(wdActiveEndPageNumber)

' If the page numbers are different we're on a new page, so
' that means the previous row must be at the bottom of the
' previous page
If lngBasePageNo <> lngCurrentPageNo Then

' Set the previous rows bottom margin to a single line
SetLine rowItem

' Set new base so that we can detect the end of this page
lngBasePageNo = lngCurrentPageNo
Else

' Always reset the bottom margin to nothing
' in case the tables expanded or shrunk
rowItem.Cells.Borders(wdBorderBottom).LineStyle = _
wdLineStyleNone
End If

' Set border for the very last row of the table
If lngRowIndex = tblTemp.Rows.Count Then SetLine rowItem
Next
Next
End Sub

Private Sub SetLine(ByVal rowItem As Word.Row)
With rowItem.Cells.Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
End Sub


Make sure you copy both procedures! For aesthetics sake I've also added a
border at the botttom of the very last row of the table. I've not added a
border at the top of the first table row, because these are often header
rows and consequently are formatted quite differently.

Note: This code reformats ALL tables in your document.

HTH + Cheers - Peter
 
J

JGM

Hi synnamone and Peter,

Sorry to butt in... but... this is something I have used many times before.

But I guess I do not understand what synnamone wants, because it seems too
easy to do.

Just in case both of you missed it, at the risk of sounding silly, here it
goes:

Select the whole table;
Call up the Borders & Shading dialog box (Format menu);
Apply only a bottom border to the table (no horizontal or top or left or
right or vertical... I mean it!);
Click OK;
Add rows to your table until it overflows onto second page;
Now you should have a border at the bottom of the last row on the first page
and at the bottom of the table itself on the second page as well.

Isn't that the behaviour you wanted?

Cheers!
--
_______________________________________
Jean-Guy Marcil
(e-mail address removed)

synnamone said:
Does anyone out there know if there's a way to automagically have Word
apply a bottom border to the last row on each page of a table that spans
multiple pages (Note: There are no internal horizontal lines in the format
we're using)??? Short of going to the the last row on each page and putting
it in manually; I can't figure it out. HELP!!!
 
P

Peter Hewett

Hi JGM

I laughed so hard I nearly fell of my seat (after writing all that code!)
Yeah, your dead right, your suggestion works perfectly!!!!

Thanks - 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