Border Around Method

This method adds a border to a range and optionally sets the Color, LineStyle, and Weight properties for the border. The syntax is:

RangeObject.BorderAround(LineStyle, Weight, ColorIndex, Color)

The LineStyle parameter can be one of the following XlLineStyle constants (note that the Excel documentation refers to a nonexistent XlBorderLineStyle enum):

Enum XlLineStyle xlLineStyleNone = -4142 xlDouble = -4119 xlDot = -4118 xlDash = -4115

xlContinuous = 1 ' the default xlDashDot = 4 xlDashDotDot = 5 xlSlantDashDot = 13 End Enum

The optional Weight parameter specifies the border weight and can be one of the following

XlBorderWeight constants:

Enum XlBorderWeight xlMedium = -4138 xlHairline = 1

xlThin = 2 ' the default xlThick = 4 End Enum

Note that the Weight property is ignored unless the LineStyle is xlContinuous or omitted.

The optional Colorlndex parameter specifies the border color, either as an index into the current color palette or as one of the following XlColorIndex constants:

Enum XlColorIndex xlColorIndexNone = -4142 xlColorIndexAutomatic = -4105 End Enum

The optional Color parameter also specifies the border color as an RGB value. Note that you should specify at most one of the color parameters.

The technique for clearing a border is a bit unexpected. For instance, suppose we have set a border with:

rng.BorderAround LineStyle:=xlDash To clear this border, we might naturally try: rng.BorderAround LineStyle:=xlLineStyleNone but this does nothing. Instead, we must write: rng.Borders.LineStyle = xlLineStyleNone which clears the borders around each cell in the range separately.

0 0

Post a comment