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.
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.
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
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.
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.
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.
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.
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.
QuickStyle returns or sets a Boolean that represents whether the style corresponds to an available quick style.
Type returns the style type.
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.