Link to home
Start Free TrialLog in
Avatar of TeDeSm
TeDeSm

asked on

How to set borders in a Word table

I am porting over some code from VBA to VB.Net in a VS2008 project.
I am automating a Word 2007 document where a table is inserted and then adding rows as required. Each row added is to have a dotted line underneath. The attached code is from VBA but VS complains of (wdBorderBottom). What would the correct syntax be please?

I had thought it would be like below, but that syntax throws an exception.
.Tables(1).Rows(r).Borders("wdBorderBottom").LineStyle = Word.WdLineStyle.wdLineStyleDot
With objWord.ActiveDocument
.Tables(1).Rows(I).Select
.Tables(1).Rows(i).Borders(wdBorderBottom).LineStyle = wdLineStyleDot
.ActiveWindow.Selection.InsertRowsBelow
End With

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Try:

Word.WdBorderType.wdBorderBottom

Chris
Avatar of ydsonline
ydsonline

You can also try:

Selection.InsertRowsBelow 1
    With Selection.Cells

        With .Borders(wdBorderBottom)
            .LineStyle = wdLineStyleDot
         End With
    End With

Open in new window

Avatar of TeDeSm

ASKER

Chris,
Can't seem to get that syntax to work within my table as wdBorderType.wdBorderBottom appears to be read only.
Regards
ASKER CERTIFIED SOLUTION
Avatar of irudyk
irudyk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What syntax did you use .. it replaces wdBorderBottom therefore:

Chris
With objWord.ActiveDocument 
.Tables(1).Rows(I).Select 
.Tables(1).Rows(i).Borders(wdBorderType.wdBorderBottom ).LineStyle = wdLineStyleDot 
.ActiveWindow.Selection.InsertRowsBelow 
End With

Open in new window

Avatar of TeDeSm

ASKER

Spot on, I was so nearly there at one time but missed it.

Good solution.
Avatar of TeDeSm

ASKER

Hi Chris,
Needed the Word. reference included.
Thanks
Not happy !

You asked "attached code is from VBA but VS complains of (wdBorderBottom). What would the correct syntax be please?"

The correct syntax I gave you as Word.WdBorderType.wdBorderBottom and although in my last post I overlooked a fiull paste in your code I did post the syntax for the question as posted in that first post

Chris