Publisher (的 TextStyles 物件)
TextStyle 一群 代表文件中的內建和使用者定義樣式的物件。
註解
使用 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 支援與意見反應。