No Visa Required For These Borders

The Range object has a property and a method that you can use to manipulate range borders—specifically, the Borders property and the BordersAround method. The Borders property returns a collection of Border objects. In order to do any serious border manipulation you'll work with a Border object. In keeping with the theme of the previous sections, the Border object is your programmatic equivalent of the Border tab of the Format Cells dialog box in Excel (see Figure 10.7).

To modify a border, you first must obtain a Range object that refers to the cells containing the border. Then you use the Borders property, which refers to a Borders collection object. In order to specify a particular border, you can use one of the XLBordersIndex constants listed in Table 10.4.

Once you have a border to work with, you can perform a handful of actions. You can set its color using either the Color or ColorIndex properties, change the style of the border using the LineStyle property, or modify the thickness of the border using the Weight property.

Figure 10.7

The Border tab of the Format Cells dialog box.

Figure 10.7

The Border tab of the Format Cells dialog box.

Table 10.4: XLBordersIndex Constants That Specify Borders

Constant used to xlDiagonalDown A diagonal line through the range starting at the upper-left corner and ending in the bottom-right corner.

xlDiagonalUp A diagonal line through the range starting at the bottom-left corner and ending in the top-right corner.

xlEdgeBottom The bottom edge of a range.

xlEdgeLeft The left edge of a range.

xlEdgeRight The right edge of a range.

xlEdgeTop The top edge of a range.

To change the LineStyle property, you use one of the XLLineStyle constants. Listing 10.5 shows an example that demonstrates all of the various line styles.

0 0

Post a comment