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 main procedures of class Style are Delete and Styles.Add

Set

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 and Document.Styles

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

Themes

The following procedures in this class have been grouped together and are described on a separate theme page

Format with its procedures BaseStyle, Borders, Font, LinkStyle, NextParagraphStyle, NoSpaceBetweenParagraphsOfSameStyle, ParagraphFormat and QuickStyle

Methods

These are the main methods of the Style class

Delete - Deletes the specified style.

ActiveDocument.Range.Paragraphs.Style.Delete

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

Dim strName As String: strName =  
Dim sty As Style
Set sty = ActiveDocument.Styles.Add(Name:=strName)

Other Methods

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

ActiveDocument.Range.Paragraphs.Style.LinkToListTemplate ListTemplate:=

Properties

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

ActiveDocument.Range.Paragraphs.Style.AutomaticallyUpdate = True

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

Dim booBuiltIn As Boolean
booBuiltIn = ActiveDocument.Range.Paragraphs.Style.BuiltIn

Description returns the description of the specified style.

Dim strDescription As String
strDescription = ActiveDocument.Range.Paragraphs.Style.Description

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

Dim frmFrame As Frame
Set frmFrame = ActiveDocument.Range.Paragraphs.Style.Frame

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.

Dim booInUse As Boolean
booInUse = ActiveDocument.Range.Paragraphs.Style.InUse

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

ActiveDocument.Range.Paragraphs.Style.LanguageID = wdAfrikaans

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

ActiveDocument.Range.Paragraphs.Style.LanguageIDFarEast = wdAfrikaans

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

Dim booLinked As Boolean
booLinked = ActiveDocument.Range.Paragraphs.Style.Linked

ListLevelNumber returns the list level for the specified style.

Dim lngListLevelNumber As Long
lngListLevelNumber = ActiveDocument.Range.Paragraphs.Style.ListLevelNumber

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

Dim lteListTemplate As ListTemplate
Set lteListTemplate = ActiveDocument.Range.Paragraphs.Style.ListTemplate

Locked true if a style cannot be changed or edited.

ActiveDocument.Range.Paragraphs.Style.Locked = True

NameLocal returns the name of a built-in style in the language of the user.

ActiveDocument.Range.Paragraphs.Style.NameLocal =

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

ActiveDocument.Range.Paragraphs.Style.NoProofing =

Parent returns an object that represents the parent object of the specified Style object.

Dim objParent As Object
Set objParent = ActiveDocument.Range.Paragraphs.Style.Parent

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

ActiveDocument.Range.Paragraphs.Style.Priority =

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

Dim shdShading As Shading
Set shdShading = ActiveDocument.Range.Paragraphs.Style.Shading

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

Dim tblstyTable As TableStyle
Set tblstyTable = ActiveDocument.Range.Paragraphs.Style.Table

Type returns the style type.

Dim wstType As WdStyleType
wstType = ActiveDocument.Range.Paragraphs.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.

ActiveDocument.Range.Paragraphs.Style.UnhideWhenUsed = True

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

ActiveDocument.Range.Paragraphs.Style.Visibility = True

Styles.Count returns a Long that represents the number of styles in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Styles.Count

Styles.Parent returns an object that represents the parent object of the specified Styles object.

Dim objParent As Object
Set objParent = ActiveDocument.Styles.Parent