Border 对象 (Excel)

表示对象边框。

备注

大多数边框对象 (除 RangeStyle 对象之外的所有对象) 具有被视为单个实体的边框,而不管它有多少边。 整个边框必须作为一个单元。

使用 Border 属性(例如来自 TrendLine 对象)可返回此类对象的 Border 对象。

请注意, Border 对象的视觉属性是联锁的;也就是说,更改一个属性可能会引发另一个属性的更改。 在大多数情况下,诱发的更改有助于使边框可见 () 可能或可能不需要。 但是,其他 (可能更意外) 结果。

下面是与意外结果互锁的示例。 在此示例中,将边框的 Weight 属性设置为 xlThick 会诱使 LineStyle 属性变为 xlSolid,尽管之前已将其设置为 xlDashDotDot。

   Sub InterlockingExample()
       Dim SomeRange As Range
       Dim SomeBorder As Border
       
       Set MyRange = Selection
       Set SomeBorder = MyRange.Borders(xlDiagonalDown)
       SomeBorder.Color = RGB(255, 0, 0)
       Debug.Print "SomeBorder.LineStyle = " & SomeBorder.LineStyle   'SomeBorder.LineStyle = 1
       Debug.Print "Set SomeBorder.LineStyle = xlDashDotDot"          'Set SomeBorder.LineStyle = xlDashDotDot
       SomeBorder.LineStyle = xlDashDotDot
       Debug.Print "SomeBorder.LineStyle = " & SomeBorder.LineStyle   'SomeBorder.LineStyle = 5
       Debug.Print "Set SomeBorder.Weight = xlThick"                  'Set SomeBorder.Weight = xlThick
       SomeBorder.Weight = xlThick
       Debug.Print "SomeBorder.LineStyle = " & SomeBorder.LineStyle   'SomeBorder.LineStyle = 1
   End Sub

示例

下例更改活动图表中趋势线的类型和线型。

With ActiveChart.SeriesCollection(1).Trendlines(1) 
 .Type = xlLinear 
 .Border.LineStyle = xlDash 
End With

RangeStyle 对象具有四个离散边框(左、右、上和下),可以单独返回或作为一组返回。 使用 Borders 属性可返回 Borders 集合,该集合包含所有四个边框,并将这些边框视为一个单位。 下例向第一张工作表上的单元格 A1 添加双边框。

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

使用 Borders (索引) (其中 index 标识边框)返回单个 Border 对象。 下例设置单元格区域 A1:G1 的底部边框的颜色。

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

Index 可以是以下 XlBordersIndex 常量之一: xlDiagonalDownxlDiagonalUpxlEdgeBottomxlEdgeLeftxlEdgeRightxlEdgeTopxlInsideHorizontalxlInsideVertical

属性

另请参阅

支持和反馈

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