Table of contents
TOC
折叠目录
展开目录

Font2.Fill 属性 (办公室)Font2.Fill Property (Office)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

获取指定文本的字体的格式设置属性。只读Gets the formatting properties for the font of the specified text. Read-only

语法Syntax

表达式填充expression. Fill

表达式_该表达式返回一个Font2对象。_expression An expression that returns a Font2 object.

示例Example

下面的代码假定一个形状已经插入 sheet1 中,它向该形状中插入文本,将字体更改为粗体并将字体的前景色更改为红色。然后,该代码在第二个单词后添加一个回车符,创建第二个段落,并使该段落右对齐。The following code assumes that a shape has been inserted into sheet1. The code inserts text into the shape and changes the fore color of the font to bold and red. It then adds a carriage return after the second word creating a second paragraph and aligns the paragraph to the right.

Sub TestShapeAttributes() 
 Dim shp As Excel.Shape 
 Dim rng As Office.TextRange2 
 Dim rngWord As Office.TextRange2 
 Dim rngRun As Office.TextRange2 
 Dim rngPara As Office.TextRange2 
 Dim fnt As Office.Font2 

 Set shp = ActiveSheet.Shapes(1) 
 Set rng = shp.TextFrame2.TextRange 
 rng.Text = "This is test text." 

 Set rngWord = rng.Words(2) 
 Set fnt = rngWord.Font 
 With fnt 
 .Fill.ForeColor.RGB = RGB(255, 0, 0) 
 .Bold = msoTrue 
 End With 

 Set rngRun = rng.Runs(3) 
 rngRun.InsertBefore vbCr 

 Set rngPara = rng.Paragraphs(2) 
 rngPara.ParagraphFormat.Alignment = msoAlignRight 
End Sub 

另请参阅See also

概念Concepts

Font2 对象Font2 Object

其他资源Other resources

Font2 对象成员Font2 Object Members

© 2018 Microsoft