border

N

Nathan Franklin

Hey list,

I am trying to set a border for a couple of rows in my table

My table has 4 columns and x rows....

the code below will only yield a a border on the bottom row of the table....
how can is et particular border for particular rows....

so far I have tried this

WordRow.Cells.Item(1).Range.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle
= Word.WdLineStyle.wdLineStyleSingle

WordRow.Cells.Item(1).Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle
= Word.WdLineStyle.wdLineStyleSingle

WordRow.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle =
Word.WdLineStyle.wdLineStyleSingle

WordRow.Range.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle =
Word.WdLineStyle.wdLineStyleSingle

I have also set the BorderWidth Property and visible property and color
property...

When I open up my document there is only a border on the bottom table row..



any help would be appreciated thanks...

nath
 
J

Jean-Guy Marcil

Nathan Franklin was telling us:
Nathan Franklin nous racontait que :
Hey list,

I am trying to set a border for a couple of rows in my table

My table has 4 columns and x rows....

the code below will only yield a a border on the bottom row of the
table.... how can is et particular border for particular rows....

so far I have tried this

WordRow.Cells.Item(1).Range.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle
= Word.WdLineStyle.wdLineStyleSingle

WordRow.Cells.Item(1).Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle
= Word.WdLineStyle.wdLineStyleSingle

WordRow.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle =
Word.WdLineStyle.wdLineStyleSingle

WordRow.Range.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle
= Word.WdLineStyle.wdLineStyleSingle

I have also set the BorderWidth Property and visible property and
color property...

When I open up my document there is only a border on the bottom table
row..


any help would be appreciated thanks...

How is WordRow being set?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
N

Nathan Franklin

Hey Jean,

WordRow is set like this

WordRow = Doc.Tables.Item(1).Rows.Add

Nath
 
J

Jean-Guy Marcil

Nathan Franklin was telling us:
Nathan Franklin nous racontait que :
Hey Jean,

WordRow is set like this

WordRow = Doc.Tables.Item(1).Rows.Add

OK. When you add a row, word formats the new last row like what used to be
the last row.

In this case, if Cells(1) of the last row has a bottom border, when Word
adds a row, the new Cells(1) also has a bottom border. But, what used to be
Cells(1) of the last row (now the one before last) does not have a bottom
border anymore because wdBorderBottom applies only to the last row of the
selection
For example, if you select 3 rows and use wdBorderBottom, only the third row
will have a "bottom" border. Whereas if you had used wdBorderHorizontal,
then row 1 and 2 would have had a "bottom" border. To get all three rows
with a "bottom border", you have to use both wdBorderHorizontal and
wdBorderBottom.

To see what I mean, add a table to a page, apply a bottom border to the last
row, place the cursor in the last cell of this last row and hit TAB to add a
row manually, see the new last row has a bottom border, but the row before
last that used to have a border does not have on anymore?
Delete the table, insert a new one, now add a bottom border to the last two
rows of the table. Add a row with TAB and see the diffrence.

So, if you add a row, and you want what used to be the last cell of the row
to keep its bottom border, if it had one, try this:
'_______________________________________
Dim Doc As Document
Dim WordRow As Row
Dim LastRow As Row
Dim CellBorder As Long

Set Doc = ActiveDocument
With Doc.Tables(1)
Set WordRow = .Rows(.Rows.Count)
CellBorder = WordRow.Cells(1).Borders(wdBorderBottom).LineStyle

Set LastRow = .Rows.Add

LastRow.Cells(1).Borders(wdBorderBottom) _
.LineStyle = wdLineStyleSingle
WordRow.Cells(1).Borders(wdBorderBottom) _
.LineStyle = CellBorder
End With
'_______________________________________

To use wdBorderHorizontal, your selection must have at least two cells in
two consecutive rows. If you have only one cell, nothing will happen as
there isn't an horizontal border separating two cells, and if you try it
with only one cell in the last row, you get an error because there cannot be
an horizontal border between two cells when the first cell in the selection
is in the last row.

I do not know if what I wrote makes any sense, if does not, try stepping
through the code a few times, then try again but comment out
WordRow.Cells(1).Borders(wdBorderBottom) _
.LineStyle = CellBorder
to see the difference.

Also, try this code with different types of cell selection to see how it
works:

Selection.Cells.Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle

Finally, the same applies to Top, Left, Right (These last two are related to
wdBorderVertical)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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