Publisher (的 TextStyle 物件)
代表單一內建或使用者定義的樣式。 TextStyle 物件會包含 style 屬性 (字型、 字型樣式、 段落間距等等) 作為 TextStyle 物件的屬性。
TextStyle 物件是 TextStyles 成員 集合。 TextStyles 集合包含在指定的文件中的所有樣式。
註解
使用 TextStyles (索引) ,其中 index 是文字樣式編號或名稱,可傳回單一 TextStyle 物件。 您必須完全符合的拼字檢查、 間距的樣式名稱,但不是一定大小寫。
使用 TextStyles.Add 方法來建立新樣式。
若要將樣式套用至範圍、段落或多個段落,請將 ParagraphFormat.TextStyle 屬性設定為使用者定義或內建樣式名稱。
範例
下列範例會顯示 TextStyles 集合中的樣式名稱和基本樣式的第一個樣式。
Sub BaseStyleName()
With ActiveDocument.TextStyles(1)
MsgBox "Style name= " & .Name _
& vbCr & "Base style= " & .BaseStyle
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 支援與意見反應。