Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
A collection of four Border objects that represent the four borders of a Range, Style, or FormatCondition object.
Remarks
Use the Borders property to return the Borders collection, which contains all four borders. You can apply different borders to each side of a cell or range. For more information how to apply borders to a range of cells, see Range.Borders property.
With Range, Style, and FormatCondition objects, you can set border properties for an individual border. Some other bordered objects, such as error bars and series lines, have a border that's treated as a single entity, regardless of how many sides it has. For those objects, you must return and set properties for the entire border as a unit. For more information, see the Border object.
Examples
The following example adds a double border to cell A1 on worksheet one.
Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
Use Borders (index), where index identifies the border, to return a single Border object. The valid values for index are determined by the parent object of the Borders collection. For Range.Borders and Style.Borders, index can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlInsideHorizontal, or xlInsideVertical. For FormatCondition.Borders, use xlLeft, xlRight, xlTop, or xlBottom.
The following example sets the color of the bottom border of cells A1:G1 to red.
Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
The following example generates a thin border around all cells in the range.
Dim rng As Range: Set rng = ws.Range("B6", "D8")
With rng.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
The following example changes only the inner cell borders of the range.
Dim rngInner As Range: Set rngInner = ws.Range("B2", "D4")
With rngInner.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With rngInner.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
Properties
- Application
- Color
- ColorIndex
- Count
- Creator
- Item
- LineStyle
- Parent
- ThemeColor
- TintAndShade
- Value
- Weight
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.