Style Object
Word Developer Reference |
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.
Remarks
Use Styles(Index), where Index is the style name, a WdBuiltinStyle constant or index number, to return a single Style object. You must exactly match the spelling and spacing of the style name, but not necessarily its capitalization. The following example modifies the font name of the user-defined style named "Color" in the active document.
Visual Basic for Applications |
---|
|
The following example sets the built-in Heading 1 style to not be bold.
Visual Basic for Applications |
---|
|
The style index number represents the position of the style in the alphabetically sorted list of style names. Note that Styles(1)
is the first style in the alphabetical list. The following example displays the base style and style name of the first style in the Styles collection.
Visual Basic for Applications |
---|
|
To apply a style to a range, paragraph, or multiple paragraphs, set the Style property to a user-defined or built-in style name. The following example applies the Normal style to the first four paragraphs in the active document.
Visual Basic for Applications |
---|
|
The following example applies the Heading 1 style to the first paragraph in the selection.
Visual Basic for Applications |
---|
|
The following example creates a character style named "Bolded" and applies it to the selection.
Visual Basic for Applications |
---|
|
Use the OrganizerCopy method to copy styles between documents and templates. Use the UpdateStyles method to update the styles in the active document to match the style definitions in the attached template. Use the OpenAsDocument method to open a template as a document so that you can modify the template styles.
See Also