Page 201 - Excel Progamming Weekend Crash Course
P. 201
k540629 ch14.qxd 9/2/03 9:34 AM Page 176
176 Saturday Afternoon
Table 14-2 Continued
Property Description
Underline A constant specifying the underlining of the font, which can be
set to xlUnderlineStyleNone, xlUnderlineStyleSingle, or
xlUnderlineStyleDouble
Strikethrough True/False value specifying whether the font is displayed with
strikethrough (horizontal lines through the characters)
Subscript True/False value specifying whether the font is displayed as a subscript
Superscript True/False value specifying whether the font is displayed as a
superscript
Specifying the name of a font requires that you know the name of the desired font.
Windows and Excel support a wide range of fonts, some of the more popular being Arial,
Courier New, Georgia, MS Sans Serif, and Times New Roman. It’s a safe bet that these and
many other fonts will be available on all Windows systems, but you cannot be sure about some
other fonts that may be installed as part of specific applications rather than as part of the
operating system. Fortunately, the Font property is very forgiving. If you assign a nonexistent
font name to this property, no error occurs—the cell displays Excel’s default font (Arial).
The Color property uses an RGB value, which identifies a color in terms of its red, green,
and blue components. To set this property, use the RGB function:
RGB(r, g, b)
Each argument is a number in the range 0 to 255 that specifies the relative level of the
red, green, or blue component. RGB(0, 0, 0) is black, RGB(255, 255, 255) is white,
RGB(122, 122, 122) is gray, RGB(0, 0, 255) is blue, and so on (you can experiment to
get some experience with the colors produced by various RGB settings). For example, this
code sets the font of the current selection to lime green:
Selection.Font.Color = RGB(122, 255, 0)
VBA provides a set of predefined constants for a few colors. They are
vbBlack, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta, vbCyan, and
Tip vbWhite. You can use these constants in place of the RGB function when
setting the Color property.
Alignment and Orientation of Data
You can control the alignment of data in a cell, both horizontally and vertically. Figure 14-3
shows the appearance of the various settings for vertical and horizontal alignment.