Description
Represents a range style description. The Style object contains all style attributes (font, number format, alignment, and so on) as properties. There are several built-in styles, including Normal, Currency, and Percent, which are listed in the Style Name box of the Style dialog box (Format menu). The Style object is a fast and efficient way to change several cell formatting properties on many cells at once.
Accessors
For a Range object, the Style property sets or returns the style used for that range. The following example applies the Percent style to cells A1:A10 on the worksheet named "Sheet1."
Worksheets("sheet1").Range("a1:a10").Style = "percent"
You can change the appearance of a cell by changing properties of the style applied to that cell. Keep in mind, however, that changing a style property will affect all cells already formatted with that style.
For the Workbook object, the Style object is a member of the Styles collection. The Styles collection contains all the defined styles for the workbook. Use the Add method to create a new style and add it to the collection. To access a single member of the collection, use the Styles method with the index number or name of the style as an argument.
Styles are sorted alphabetically by style name. The style index number represents the position of the specified style in the sorted list of style names. Styles(1) is the first style in the alphabetical list; Styles(Styles.Count) is the last. The following example creates a list of style names on worksheet one in the active workbook.
For i = 1 To ActiveWorkbook.Styles.Count Worksheets(1).Cells(i, 1) = ActiveWorkbook.Styles(i).Name Next
You assign a name to a style when you create it. Use the Name property to return the style name. The following example changes the Normal style by setting its Bold property.
ActiveWorkbook.Styles("Normal").Font.Bold = True
For more information about creating and modifying a style, see the Styles object.
Properties
AddIndent Property, Application Property, Creator Property, Font Property, FormulaHidden Property, HorizontalAlignment Property, IncludeAlignment Property, IncludeBorder Property, IncludeFont Property, IncludeNumber Property, IncludePatterns Property, IncludeProtection Property, Interior Property, Locked Property, Name Property, NameLocal Property, NumberFormat Property, NumberFormatLocal Property, Orientation Property, Parent Property, Value Property, VerticalAlignment Property, WrapText Property.
Methods
Borders Method, Delete Method.