表示 Range、Style 或 FormatCondition 对象的四个边框的四个 Border 对象的集合。
备注
使用 Borders 属性可返回包含所有四个边框的 Borders 集合。 可以对单元格或区域的每一侧应用不同的边框。 有关如何将边框应用于单元格区域的详细信息,请参阅 Range.Borders 属性。
使用 Range、 Style 和 FormatCondition 对象,可以设置单个边框的边框属性。 某些其他带边框的对象(例如误差线和序列线)的边框被视为单个实体,无论它有多少条边。 对于这些对象,必须返回整个边框作为一个单元并设置属性。 有关详细信息,请参阅 Border 对象。
示例
下例向第一张工作表上的单元格 A1 添加双边框。
Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
使用 Borders (index) ,其中 index 标识边框,以返回单个 Border 对象。 index 的有效值由 Borders 集合的父对象确定。 对于 Range.Borders 和 Style.Borders,index 可以是以下 XlBordersIndex 常量之一:xlDiagonalDown、xlDiagonalUp、xlEdgeBottom、xlEdgeLeft、xlEdgeRight、xlEdgeTop、xlInsideHorizontal 或 xlInsideVertical。 对于 FormatCondition.Borders,请使用 xlLeft、 xlRight、 xlTop 或 xlBottom。
下例将单元格区域 A1:G1 的底部边框颜色设置为红色。
Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
以下示例在区域内的所有单元格周围生成一个细边框。
Dim rng As Range: Set rng = ws.Range("B6", "D8")
With rng.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
以下示例仅更改区域的内部单元格边框。
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
属性
- Application
- Color
- ColorIndex
- Count
- Creator
- Item
- LineStyle
- Parent
- ThemeColor
- TintAndShade
- Value
- Weight
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。