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 / Programming / January 2006

Tip: Looking for answers? Try searching our database.

border

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Franklin - 16 Jan 2006 11:11 GMT
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
Jean-Guy Marcil - 16 Jan 2006 21:19 GMT
Nathan Franklin was telling us:
Nathan Franklin nous racontait que :

> Hey list,
>
[quoted text clipped - 26 lines]
>
> any help would be appreciated thanks...

How is WordRow being set?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Nathan Franklin - 16 Jan 2006 21:33 GMT
Hey Jean,

WordRow is set like this

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

Nath

> Nathan Franklin was telling us:
> Nathan Franklin nous racontait que :
[quoted text clipped - 31 lines]
>
> How is WordRow being set?
Jean-Guy Marcil - 16 Jan 2006 22:23 GMT
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)

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 


Rate this thread:






 
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.