Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Styles Collection

Styles Collection [Excel 2003 VBA Language Reference]

Office 2003
Workbook
Styles
Style
Multiple objects

A collection of all the Style objects in the specified or active workbook. Each Style object represents a style description for a range. 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 in the Style dialog box (Format menu).

Using the Styles Collection

Use the Styles property to return the Styles collection. 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
		

Use the Add method to create a new style and add it to the collection. The following example creates a new style based on the Normal style, modifies the border and font, and then applies the new style to cells A25:A30.

With ActiveWorkbook.Styles.Add(Name:="Bookman Top Border")
    .Borders(xlTop).LineStyle = xlDouble
    .Font.Bold = True
    .Font.Name = "Bookman"
End With
Worksheets(1).Range("A25:A30").Style = "Bookman Top Border"
		

Use Styles(index), where index is the style index number or name, to return a single Style object from the workbook Styles collection. The following example changes the Normal style for the active workbook by setting its Bold property.

ActiveWorkbook.Styles("Normal").Font.Bold = True
		


Parent Objects | Workbook

Child Objects | Borders | Font | Interior


Show:
© 2015 Microsoft