Adds a new style to the style collection of the document. Returns a Style object that corresponds to the new created style.
Applies to: Document object
[[Set] styleRet =] object.AddStyle ( styleName ) |
The AddStyle method syntax has these parts:
Part | Description |
object | Required. An expression that returns an instance of the Document object. |
styleName | Optional. An expression that returns a String value. The name (the Name property) of the new style. |
styleRet | Optional. A Style type variable. |
The AddStyle method creates a new style based on the default style (the DefStyle property). If there already is a style with the styleName name in the collection, the method doesn't create a new style and returns Nothing. If styleName is not specified, the AddStyle method assigns a unique name (the Name property) to the style automatically. The new style, created with the AddStyle method, is added to the end of the style collection of the document.
This example contains a document-level script. It demonstrates using the AddStyle method. It also shows, that it's not possible to add to the collection two styles with the same names.
' Declare variables Dim new_style As Style ' Add a style with some name Set new_style = thisDoc.AddStyle() ' Display the name of the new style TRACE new_style.Name ' Add a new style with a specified name Set new_style = thisDoc.AddStyle("Style_Name_1") ' Display the name of the reference to the instance of the ' object corresponding to the new style TRACE new_style ' Attempt to add a style with the same name Set new_style = thisDoc.AddStyle("Style_Name_1") ' Display the name of the reference to the instance of the ' object corresponding to the new style, to make sure the style ' hasn't been added TRACE new_style |
See Also |
Name property, FindStyle method, RemoveStyle method, RemoveStyleByName method, RenameStyle method, Style method, StyleByName method, StylesNum method, Style object |