Class Styles (Word VBA)

A collection of Style objects that represent both the built-in and user-defined styles in a document. To use a Styles class variable it first needs to be instantiated, for example


Dim stys as Styles
Set stys = ActiveDocument.Styles

For Each

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


Dim sty As Style
For Each sty In ActiveDocument.Range.Styles
	
Next sty

Add

Creates a new user-defined style and adds it to the Styles collection.

Add (Name, Type)


Set myStyle = ActiveDocument.Styles.Add(Name:="Introduction", _ 
 Type:=wdStyleTypeCharacter) 
With myStyle.Font 
 .Bold = True 
 .Italic = True 
 .Name = "Arial" 
 .Size = 12 
End With 
Selection.Range.Style = "Introduction"

Arguments

The following argument is required

Name (String) - The new style name.

Optional arguments

The following argument is optional

Type (WdStyleType) - Can be one of the WdStyleType constants.


Possible values are

wdStyleTypeCharacter Body character style.
wdStyleTypeLinked
wdStyleTypeList List style.
wdStyleTypeParagraph Paragraph style.
wdStyleTypeParagraphOnly
wdStyleTypeTable Table style.

Count

Returns a Long that represents the number of styles in the collection.


Dim lngCount As Long
lngCount = ActiveDocument.Styles.Count

Item

Returns an individual Style object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position or a String representing the name of the individual object.


Dim sty As Style
Set sty = ActiveDocument.Styles(Index:=1)