The Border Object

The most interesting properties and methods of the Border object are described in this section. 19.4.3.1 Color property

This property returns or sets the primary color of the border. It can also be applied to the Borders collection to set all vertical and horizontal lines for the borders at the same time. (The property also applies to Font objects and Interior objects.)

For instance, the following code has the effect shown in Figure 19-22:

.Interior.Color = RGB(196, 196, 196) With .Borders

.Weight = xlThick .Color = RGB(255, 0, 0) End With End With

Figure 19-22. Assigning the Colors property of the Borders collection

A

B

C D E

1

2

I I I

3

4

To set a color value, we use the RGB color function, which has the form:

RGB(red, green, blue)

where red, green, and blue are integers between 0 and 255, inclusive, that represent the strength of the respective color component. Table 19-4 gives some common color values.

Table 19-4. Some Common Colors

Color

Red

Green

Blue

Black

0

0

0

Blue

0

0

255

Green

0

255

0

Cyan

0

255

255

Red

255

0

0

Magenta

255

0

255

Yellow

255

255

0

White

255

255

255

To use a grayscale, set the red, green, and blue components equally. For instance:

To use a grayscale, set the red, green, and blue components equally. For instance:

will produce a 25% grayscale. (The larger the numbers, the closer to white.) Unfortunately, Excel rounds all grayscale settings to one of the following:

• 100% (black) You can see this by running the following code:

Cells(r, 1).Interior.Color =

RGB(255 - 10 * r, 255 - 10~* r, 255 - 10 * r) Cells(r, 2).Value = 255 - 10 * r Next

If you want to use grayscales often, consider adding the following constant declarations to a code module. (The numbers on the right are RGB values.)

Public Const Gray25 = 12632256 Public Const Gray40 = 9868950 Public Const Gray50 = 8421504 Public Const Gray80 = 3355443

19.4.3.2 Colorlndex property

This property sets the color by using an index into a color palette. There is no way to do justice to this in a black and white book, so I suggest you take a look at this property in Excel's help documentation, where there is a color picture. However, you can set this property to one of the following XlColorIndex constants as well:

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

19.4.3.3 LineStyle property

The LineStyle property returns or sets the line style for the border. It can be one of the following

XlLineStyle constants:

Enum XlLineStyle xlLineStyleNone = -4142 xlDouble = -4119 xlDot = -4118 xlDash = -4115 xlContinuous = 1 xlDashDot = 4 xlDashDotDot = 5 xlSlantDashDot = 13 End Enum

These values speak pretty much for themselves.

' no interior fill ' automatic fill

19.4.3.4 Weight property

The Weight property returns or sets the weight of the border. It can be one of the following

XlBorderWeight constants:

Enum XlBorderWeight xlMedium = -4138 xlHairline = 1 xlThin = 2 xlThick = 4 End Enum

0 0

Responses

Post a comment