Class Styles (Excel VBA)

A collection of all the Style objects in the specified or active workbook. To use a Styles class variable it first needs to be instantiated, for example


Dim stys as Styles
Set stys = ActiveWorkbook.Styles

For Each

Here is an example of processing the Styles items in a collection.


Dim sty As Style
For Each sty In Application.Styles
	
Next sty

Add

Creates a new style and adds it to the list of styles that are available for the current workbook.

Add (Name, BasedOn)


With ActiveWorkbook.Styles.Add("theNewStyle") 
 .IncludeNumber = False 
 .IncludeFont = True 
 .IncludeAlignment = False 
 .IncludeBorder = False 
 .IncludePatterns = False 
 .IncludeProtection = False 
 .Font.Name = "Arial" 
 .Font.Size = 18 
End With

Arguments

The following argument is required

Name (String) - The new style name.

Optional arguments

The following argument is optional

BasedOn

Count

Returns a Long value that represents the number of objects in the collection.


Dim lngCount As Long
lngCount = ActiveWorkbook.Styles.Count

Item

Returns a single Style object from the collection.

Item (Index)

Index: The name or index number of the object.


Dim styItem As Style
Set styItem = ActiveWorkbook.Styles(Index:=1)

Merge

Merges the styles from another workbook into the Styles collection.

Merge (Workbook)

Workbook: A Workbook object that represents the workbook that contains styles to be merged.


ActiveWorkbook.Styles.Merge Workbook:=Workbooks("TEMPLATE.XLS")