StyleName$()

Syntax

StyleName$([Count,] [Context,] [All])

Remarks

Returns the name of the specified style or, if no style is specified, the name of the style applied to the first paragraph in the selection. Note that if the insertion point or selection is within text formatted with a character style, StyleName$() returns the name of the character style (not the paragraph style). For a method of returning the paragraph style in this case, see the second example in this reference entry.

Argument

Explanation

Count

The position of the style in an alphabetic list of styles for the document or template, according to the value of Context. The number can range from 1 to CountStyles(), which returns the total number of styles (both character and paragraph) in the specified context. If Count is 0 (zero) or omitted, the name of the current style is returned.

Context

The list of styles to use:

0 (zero) or omitted Active document

1 Active template

All

Specifies whether to include built-in styles:

0 (zero) or omitted Built-in styles are excluded.

1 Built-in styles are included.

Note that Word contains 75 built-in styles, and that two of those built-in styles are defined by default: Default Paragraph Font and Normal.


Examples

This example checks to see if the first style in the list of document styles is used in the document. If the style is not used, a message box is displayed:


FirstStyle$ = StyleName$(1)
StartOfDocument
EditFindClearFormatting
EditFindStyle .Style = FirstStyle$
EditFind .Find = "", .WholeWord = 0, .MatchCase = 0, .Direction = 0, \
    .Format = 1, .Wrap = 0
If EditFindFound() = 0 Then
    MsgBox "Style " + FirstStyle$ + " is not in use."
End If

The following example ensures that StyleName$() returns the underlying paragraph style, regardless of any character styles applied to the current selection:


EditBookmark "tmp"
SelType 1
reset$ = StyleName$()
Style "Default Paragraph Font"
parastyle$ = StyleName$()
Style reset$
EditGoto "tmp"
EditBookmark "tmp", .Delete

See Also

CountStyles(), FormatStyle, StyleDesc$()