Text Formatting
In Excel, there are 2 types of formatting. One that applies to the text in
a cell, and one that applies to the cell itself. To apply formatting to the
text, you use the Font object. The Font object allows you to change font face,
size, bold, italic etc. For example, the following code makes the selected cell
use the Tahoma font:
ActiveCell.Font.Name = "Tahoma"
The other main properties that you can change are listed below:
|
Property Name
|
| Bold |
| Color |
| ColorIndex |
| Creator |
| Italic |
| Name |
| Size |
| Strikethrough |
| Subscript |
| Superscript |
| Underline |
For the Name and Size properties, you simply specify a font name and size.
Other properties such as Italic, are true/false properties:
Range("A1").Font.Italic = True
sets A1's text to italic. The Color property allows you to specify an actual
color. You can use the RGB function to form it:
ActiveCell.Font.Color = RGB(255,0,0)
sets the active cells font colour to Red (255 red, 0 green, 0 blue). Alternatively,
you can use the ColorIndex property. This lets you specify an item in the workbooks
palette (this can be set in the Color tab of the Excel Options dialog).
ActiveCell.Font.ColorIndex = 16
sets the font colour to the 16th item on the colour palette.