Shapes.AddLabel 方法 (Word)

在绘图画布上添加一个文本标签。

语法

表达式AddLabel (方向左侧顶部宽度高度)

expression 是必需的。 一个代表 Shapes 对象的变量。

参数

名称 必需/可选 数据类型 说明
Orientation 必需 MsoTextOrientation 文本的方向。
Left 必需 Single 标签左边缘相对于绘图画布左边缘的位置(以磅为单位)。
Top 必需 Single 标签上边缘相对于绘图画布上边缘的位置(以磅为单位)。
Width 必需 Single 标签的宽度(以磅为单位)。
Height 必需 Single 标签的高度(以磅为单位)。

返回值

Shapes

示例

本示例在活动文档的新绘图画布上添加一个蓝色的文本标签,该标签带有文字“Hello World”。

Sub NewCanvasTextLabel() 
 Dim shpCanvas As Shape 
 Dim shpLabel As Shape 
 
 'Add a drawing canvas to the active document 
 Set shpCanvas = ActiveDocument.Shapes.AddCanvas _ 
 (Left:=100, Top:=75, Width:=150, Height:=200) 
 
 'Add a label to the drawing canvas 
 Set
shpLabel = shpCanvas.CanvasItems.AddLabel _ 
 (Orientation:=msoTextOrientationHorizontal, _ 
 Left:=15, Top:=15, Width:=100, Height:=100) 
 
 'Fill the label textbox with a color, 
 'add text to the label and format it 
 With
shpLabel 
 With .Fill 
 .BackColor.RGB = RGB(Red:=0, Green:=0, Blue:=192) 
 'Make the fill visible 
 .Visible = msoTrue 
 End With 
 With .TextFrame.TextRange 
 .Text = "Hello World." 
 .Bold = True 
 .Font.Name = "Tahoma" 
 End With 
 End With 
End Sub

另请参阅

Shapes 集合对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。