Border Object

Excel Developer Reference

Represents the border of an object.


Most bordered objects (all except for the Range and Style objects) have a border that’s treated as a single entity, regardless of how many sides it has. The entire border must be returned as a unit. Use the Border property, such as from a TrendLine object, to return the Border object for this kind of object.

The following example changes the type and line style of a trend line on the active chart.

Visual Basic for Applications
  With ActiveChart.SeriesCollection(1).Trendlines(1)
    .Type = xlLinear
    .Border.LineStyle = xlDash
End With

Range and Style objects have four discrete borders — left, right, top, and bottom — which can be returned individually or as a group. Use the Borders property to return the Borders collection, which contains all four borders and treats the borders as a unit. The following example adds a double border to cell A1 on worksheet one.

Visual Basic for Applications
  Worksheets(1).Range("A1").Borders.LineStyle = xlDouble

Use Borders(


), where


identifies the border, to return a single Border object. The following example sets the color of the bottom border of cells A1:G1.

Visual Basic for Applications
  Worksheets("Sheet1").Range("A1:G1"). _
    Borders(xlEdgeBottom).Color = RGB(255, 0, 0)


can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.

See Also