Class Border (Word VBA)

The class Border represents a border of an object. The Border object is a member of the Borders collection. To use a Border class variable it first needs to be instantiated, for example


Dim brd as Border
Set brd = Selection.Borders(Index:=1)

For Each

Here is an example of processing the Border items in a collection.


Dim brd As Border
For Each brd In Selection.Borders
	    If brd.Inside = True Then brd.LineStyle = wdLineStyleSingle 
Next brd

ArtStyle

Returns or sets the graphical page-border design for a document. Here you can find possible values for WdPageBorderArt.


Selection.Borders(1).ArtStyle = wdArtApples

ArtWidth

Returns or sets the width (in points) of the specified graphical page border.


Dim borderLoop As Border 
 
For Each borderLoop In Selection.Sections(1).Borders 
 With borderLoop 
 .ArtStyle = wdArtBasicBlackDots 
 .ArtWidth = 6 
 End With 
Next borderLoop

Color

Returns or sets the 24-bit color for the specified Border object. Here you can find possible values for WdColor.

This property can be any valid WdColor constant or a value returned by Visual Basic's RGB function.


If ActiveDocument.Tables.Count >= 1 Then 
 For Each aBorder In ActiveDocument.Tables(1).Borders 
 aBorder.Color = wdColorIndigo 
 aBorder.LineStyle = wdLineStyleDashDot 
 aBorder.LineWidth = wdLineWidth075pt 
 Next aBorder 
End If

ColorIndex

Returns or sets the color for the specified border or font object. Here you can find possible values for WdColorIndex.

The wdByAuthor constant is not valid for border and font objects.


Dim borderLoop As Border 
 
If ActiveDocument.Tables.Count >= 1 Then 
 For Each borderLoop In ActiveDocument.Tables(1).Borders 
 With borderLoop 
 .ColorIndex = wdRed 
 .LineStyle = wdLineStyleDashDot 
 .LineWidth = wdLineWidth075pt 
 End With 
 Next borderLoop 
End If

Inside

True if an inside border can be applied to the specified object.


Dim borderLoop As Border 
 
For Each borderLoop In Selection.Borders 
 If borderLoop.Inside = True Then _ 
 borderLoop.LineStyle = wdLineStyleSingle 
Next borderLoop

LineStyle

Returns or sets the border line style for the specified object. Here you can find possible values for WdLineStyle.

Setting the LineStyle property for a range that refers to individual characters or words applies a character border. Setting the LineStyle property for a paragraph or range of paragraphs applies a paragraph border. Use the InsideLineStyle property to apply a border between consecutive paragraphs. Setting the LineStyle property for a section applies a page border around the pages in the section.


With Selection.Borders(wdBorderTop) 
 .LineStyle = wdLineStyleSingle 
 .LineWidth = wdLineWidth075pt 
End With

LineWidth

Returns or sets the line width of an object's border. Here you can find possible values for WdLineWidth.

Returns a WdLineWidth constant or wdUndefined if the object either has no borders or has borders with more than one line width. If the specified line width isn't available for the border's line style, this property generates an error. To determine the line widths available for a particular line style, see the Borders and Shading dialog box (Format menu).


If ActiveDocument.Tables.Count >= 1 Then 
 With ActiveDocument.Tables(1).Rows(1).Borders(wdBorderBottom) 
 .LineStyle = wdLineStyleSingle 
 .LineWidth = wdLineWidth050pt 
 End With 
End If

Visible

True if the specified object is visible.

For any object, some methods and properties may be unavailable if the Visible property is False.


Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _ 
 NumRows:=12, NumColumns:=5) 
For Each aBorder In myTable.Borders 
 aBorder.Visible = False 
Next aBorder