四个 Border 对象的集合,这些对象表示 Range 对象或 Style 对象的四个边框。

使用 Borders 属性可返回包含所有四个边框的 Borders 集合。 可以对单元格或区域的每一侧应用不同的边框。 有关如何对单元格区域应用边框的详细信息,请参阅 Range.Borders 属性。

只能对 Range Style 对象的各个边框分别设置边框属性。 其他带边框的对象(如误差线和序列线)具有被视为单个实体的边框,而不管它有多少边。 对于这些对象,在返回边框和设置边框属性时必须将其作为一个整体处理。 有关详细信息,请参阅 Border 对象。

下例向第一张工作表上的单元格 A1 添加双边框。

Worksheets(1).Range("A1").Borders.LineStyle = xlDouble

使用 Borders (索引) (其中 index 标识边框)返回单个 Border 对象。 Index 可以是以下 XlBordersIndex 常量之一: xlDiagonalDownxlDiagonalUpxlEdgeBottomxlEdgeLeftxlEdgeRightxlEdgeTopxlInsideHorizontalxlInsideVertical

下例将单元格区域 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
  • Color
  • ColorIndex
  • Count
  • Creator
  • LineStyle
  • Parent
  • ThemeColor
  • TintAndShade
  • Value
  • Weight
  • Excel 对象模型引用
  • 支持和反馈

    有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。