Border 对象 (Excel)Border object (Excel)

表示对象边框。Represents the border of an object.

注释Remarks

大多数带边框的对象 ( Range 和**Style** 对象除外) 都有一个作为单个实体处理的边框, 而不管它有多少个边。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.

使用**Border** 属性 (如从趋势线对象) 可以返回此类对象的border对象。Use the Border property, such as from a TrendLine object, to return the Border object for this kind of object.

请注意, Border对象的可视属性是联锁的;也就是说, 更改一个属性可能会引发另一个属性中的更改。Note that the visual properties of a Border object are interlocked; that is, changing one property can induce changes in another. 在大多数情况下, 引发的更改使边框可见 (可能是也可能不需要)。In most cases, the induced changes serve to make the border visible (which may or may not be desirable). 但是, 其他 (更意外的) 结果可能是可行的。However, other (more unexpected) results are possible.

以下是使用意外结果进行连锁的示例。Following is an example of interlocking with unexpected results. 在此示例中, 如果将边框的权重属性设置为 xlThick, 则LineStyle属性将成为 xlSolid, 而不是之前将其设置为 xlDashDotDot。In this example, setting a border's Weight property to xlThick induces the LineStyle property to become xlSolid despite having previously set it to 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

示例Example

下例更改活动图表中趋势线的类型和线型。The following example changes the type and line style of a trend line on the active chart.

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

RangeStyle对象具有四个离散边框-left、right、top 和底端—可以分别返回, 也可以作为一个组返回。Range and Style objects have four discrete borders—left, right, top, and bottom—which can be returned individually or as a group. 使用 Borders 属性可返回 Borders 集合,该集合包含所有四个边框,并将这些边框视为一个单位。Use the Borders property to return the Borders collection, which contains all four borders and treats the borders as a unit. 下例向第一张工作表上的单元格 A1 添加双边框。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. 下例设置单元格区域 A1:G1 的底部边框的颜色。The following example sets the color of the bottom border of cells A1:G1.

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

_索引_可以是下列**XlBordersIndex** 常量之一: xlDiagonalDownxlDiagonalUpxlEdgeBottomxlEdgeLeftxlEdgeRightxlEdgeTopxlInsideHorizontal、或xlInsideVerticalIndex can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.

属性Properties

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.