Font 对象(Word)Font object (Word)

包含对象的字体属性(如字体名称、字号、颜色等)。Contains font attributes (such as font name, font size and color) for an object.


使用 Font 属性返回 Font 对象。Use the Font property to return the Font object. 以下说明将粗体格式应用于所选内容。The following instruction applies bold formatting to the selection.

Selection.Font.Bold = True

以下示例将活动文档中第一个段落的格式设置为 24 磅、Arial 和倾斜。The following example formats the first paragraph in the active document as 24point Arial and italic.

Set myRange = ActiveDocument.Paragraphs(1).Range 
With myRange.Font 
 .Bold = True 
 .Name = "Arial" 
 .Size = 24 
End With

以下示例将活动文档中“标题 2”样式的格式更改为 Arial 字体和加粗。The following example changes the formatting of the Heading 2 style in the active document to Arial and bold.

With ActiveDocument.Styles(wdStyleHeading2).Font 
 .Name = "Arial" 
 .Italic = True 
End With

你可以使用 New 关键字来创建一个新的独立 Font 对象。You can use the New keyword to create a new, stand-alone Font object. 下例创建 Font 对象,设置一些格式化属性,然后将 Font 对象应用于活动文档的第一个段落。The following example creates a Font object, sets some formatting properties, and then applies the Font object to the first paragraph in the active document.

Set myFont = New Font 
myFont.Bold = True 
myFont.Name = "Arial" 
ActiveDocument.Paragraphs(1).Range.Font = myFont

您还可以通过使用重复的属性来复制Font对象。You can also duplicate a Font object by using the Duplicate property. 下例使用所选内容的字符格式以及斜体格式创建新字符样式。The following example creates a new character style with the character formatting from the selection and italic formatting. 所选内容的格式未更改。The formatting of the selection is not changed.

Set aFont = Selection.Font.Duplicate 
aFont.Italic = True 
ActiveDocument.Styles.Add(Name:="Italics", _ 
 Type:=wdStyleTypeCharacter).Font = aFont

另请参阅See also

Word 对象模型参考Word Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.