Class Style (Word VBA)

The class Style represents a single built-in or user-defined style. The Style object includes style attributes (such as font, font style, and paragraph spacing) as properties of the Style object. The Style object is a member of the Styles collection. The Styles collection includes all the styles in the specified document.

The classes EmailAuthor, EmailOptions, Envelope, Find, HeadingStyle, Paragraph, ParagraphFormat, Range, Replacement, Revision, Selection and Table. give access to class Style

To use a Style class variable it first needs to be instantiated, for example

Dim sty as Style
Set sty = Application.ActiveDocument.Range.Paragraphs
The following procedures can be used to set variables of type Style: EmailAuthor.Style, EmailOptions.ComposeStyle, EmailOptions.PlainTextStyle, EmailOptions.ReplyStyle, Envelope.AddressStyle, Envelope.ReturnAddressStyle, Find.Style, HeadingStyle.Style, Paragraph.Style, ParagraphFormat.Style, Paragraphs.Style, Range.Style, Replacement.Style, Revision.Style ...Selection.Style, Styles.Add, Styles.Item, Table.Style.

For Each

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

Dim strMessage As String 
Dim sty As Style  
strMessage = "Styles in use:" & vbCr 
 For Each sty In ActiveDocument.Styles 
 If sty.InUse = True Then 
 With docActive 
 .Content.Find 
 .ClearFormatting 
 .Text = "" 
 .Style = sty 
 .Execute Format:=True 
 If .Found = True Then 
 strMessage = strMessage & sty.Name & vbCr 
 End If 
 End With 
 End If 
Next sty  
MsgBox strMessage

Methods

Delete - Deletes the specified style.

LinkToListTemplate - Links the specified style to a list template so that the style's formatting can be applied to lists.

Properties

NameLocal (Default member) - Returns the name of a built-in style in the language of the user.

AutomaticallyUpdate true if the style is automatically redefined based on the selection.

BaseStyle returns or sets an existing style on which you can base the formatting of another style.

Borders returns a Borders collection that represents all the borders for the specified style.

BuiltIn true if the specified object is one of the built-in styles or caption labels in Word.

Description returns the description of the specified style.

Font returns or sets a Font object that represents the character formatting of the specified style.

Frame returns a Frame object that represents the frame formatting for the specified style.

InUse true if the specified style is a built-in style that has been modified or applied in the document or a new style that has been created in the document.

LanguageID returns or sets a WdLanguageID constant that represents the language for the specified range.

LanguageIDFarEast returns or sets an East Asian language for the specified object.

Linked returns a Boolean that represents whether a style is a linked style that can be used for both paragraph and character formatting.

LinkStyle sets or returns a Variant that represents a link between a paragraph and a character style.

ListLevelNumber returns the list level for the specified style.

ListTemplate returns a ListTemplate object that represents the list formatting for the specified Style object.

Locked true if a style cannot be changed or edited.

NextParagraphStyle returns or sets the style to be applied automatically to a new paragraph that is inserted after a paragraph formatted with the specified style.

NoProofing true if the spelling and grammar checker ignores text formatted with this style.

NoSpaceBetweenParagraphsOfSameStyle true for Microsoft Word to remove spacing between paragraphs that are formatted using the same style.

ParagraphFormat returns or sets a ParagraphFormat object that represents the paragraph settings for the specified style.

Priority returns or sets a Long that represents the priority for sorting styles in the Styles task pane.

QuickStyle returns or sets a Boolean that represents whether the style corresponds to an available quick style.

Shading returns a Shading object that refers to the shading formatting for the specified object.

Table returns a TableStyle object representing properties that can be applied to a table using a table style.

Type returns the style type.

UnhideWhenUsed true if the specified style is made visible as a recommended style in the Styles and in the Styles task pane in Word after it is used in the document.

Visibility true if the specified style is visible as a recommended style in the Styles gallery and in the Styles task pane.

Borders - A collection of Border objects that represent the borders of an object.

Font - Contains font attributes (such as font name, font size and color) for an object.

Frame - Represents a frame. The Frame object is a member of the Frames collection. The Frames collection includes all frames in a selection, range, or document.

ListTemplate - Represents a single list template that includes all the formatting that defines a list. The ListTemplate object is a member of the ListTemplates collection.

ParagraphFormat - Represents all the formatting for a paragraph.

Shading - Contains shading attributes for an object.

TableStyle - Represents a single style that can be applied to a table.