TextStyles 对象 (Publisher)
文本样式 的集合 对象表示文档中的内置和用户定义样式。
备注
使用 Document.TextStyles 属性可返回 TextStyles 集合。
使用 添加 若要创建新的用户定义样式并将其添加到 TextStyles 集合的方法。
示例
下面的示例创建一个表格,列出了当前出版物中的所有样式。
Sub ListTextStyles()
Dim sty As TextStyle
Dim tbl As Table
Dim intRow As Integer
With ActiveDocument
Set tbl = .Pages(1).Shapes.AddTable(NumRows:=.TextStyles.Count, _
NumColumns:=2, Left:=72, Top:=72, Width:=488, Height:=12).Table
For Each sty In .TextStyles
intRow = intRow + 1
With tbl.Rows(intRow)
.Cells(1).text = sty.Name
.Cells(2).text = sty.BaseStyle
End With
Next sty
End With
End Sub
下面的示例创建一个新样式,并将其应用到光标位置所在的段落。
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
方法
属性
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈