TextStyle object (Publisher)

Represents a single built-in or user-defined style. The TextStyle object includes style attributes (font, font style, paragraph spacing, and so on) as properties of the TextStyle object.

The TextStyle object is a member of the TextStyles collection. The TextStyles collection includes all the styles in the specified document.

Remarks

Use TextStyles (index), where index is the text style number or name, to return a single TextStyle object. You must exactly match the spelling and spacing of the style name, but not necessarily its capitalization.

Use the TextStyles.Add method to create a new style.

To apply a style to a range, paragraph, or multiple paragraphs, set the ParagraphFormat.TextStyle property to a user-defined or built-in style name.

Example

The following example displays the style name and base style of the first style in the TextStyles collection.

Sub BaseStyleName() 
 With ActiveDocument.TextStyles(1) 
 MsgBox "Style name= " & .Name _ 
 & vbCr & "Base style= " & .BaseStyle 
 End With 
End Sub

The following example creates a new style and applies it to the paragraph at the cursor position.

Sub ApplyTextStyle() 
 Dim styNew As TextStyle 
 Dim fntStyle As Font 
 
 'Create a new style 
 Set styNew = ActiveDocument.TextStyles.Add(StyleName:="NewStyle") 
 Set fntStyle = styNew.Font 
 
 'Format the Font object 
 With fntStyle 
 .Name = "Tahoma" 
 .Size = 20 
 .Bold = msoTrue 
 End With 
 
 'Apply the Font object formatting to the new style 
 styNew.Font = fntStyle 
 
 'Apply the new style to the selected paragraph 
 Selection.TextRange.ParagraphFormat.TextStyle = "NewStyle" 
End Sub

Methods

Properties

See also

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.