Applies To
Range Object.
Description
Adds a border to a range and sets the Color, LineStyle, and Weight properties for the new border.
Syntax
object.BorderAround(lineStyle, weight, colorIndex, color)
object
Required. The Range object.
lineStyle
Optional. Specifies the border line style. Can be one of xlContinuous, xlDash, xlDot, or xlDouble.
weight
Optional. Specifies the border weight. Can be one of xlHairline, xlThin, xlMedium, or xlThick. If omitted, xlThin is assumed.
colorIndex
Optional. Specifies the border color as a color index into the current color palette. Can be a number from 1 to 56, or the special constant xlAutomatic to use the window text color.
color
Optional. Specifies the border color as an RGB value.
Remarks
You can specify either colorIndex or color, but not both. If you do not specify either argument, Microsoft Excel uses the xlAutomatic color index.
Similarly, you can specify either lineStyle or weight, but not both. If you do not specify either argument, Microsoft Excel creates a default border.
This method outlines the entire range without filling it in. To set the borders of all the cells, you must set the Color, LineStyle, and Weight properties for the Borders collection. To clear the border, you must set the LineStyle property to xlNone for all the cells in the range.
Example
This example adds a thick red border around the range A1:D4 on Sheet1.
Worksheets("Sheet1").Range("A1:D4").BorderAround _ ColorIndex:=3, Weight:=xlThick