应用于 CanvasShapes 对象的 AddLabel 方法。
在画布上添加一个文本标签。返回一个 Shape 对象,该对象代表画布,并将其添加至 CanvasShapes 集合。
expression.AddLabel(Orientation, Left, Top, Width, Height)
expression 必需。该表达式返回一个 CanvasShapes 对象。
Orientation MsoTextOrientation,必需。文本的方向。
| MsoTextOrientation 可以是下列 MsoTextOrientation 常量之一: |
| msoTextOrientationDownward |
| msoTextOrientationHorizontal |
| msoTextOrientationHorizontalRotatedFarEast |
| msoTextOrientationMixed |
| msoTextOrientationUpward |
| msoTextOrientationVertical |
| msoTextOrientationVerticalFarEast |
| 由于选择或安装的语言支持不同,例如,英语(美国),有些常量可能无法使用。 |
Left Single 类型,必需。标签左边缘相对于画布左边缘的位置,以磅为单位。
Top Single 类型,必需。标签上边缘相对于画布上边缘的位置,以磅为单位。
Width Single 类型,必需。标签的宽度,以磅为单位。
Height Single 类型,必需。标签的高度,以磅为单位。
在文档中添加一个文本标签。返回一个 Shape 对象,该对象代表文本标签,并将其添加至 Shapes 集合。
expression.AddLabel(Orientation, Left, Top, Width, Height, Anchor)
expression 必需。该表达式返回一个 Shapes 对象。
Orientation MsoTextOrientation,必需。文本的方向。
| MsoTextOrientation 可以是下列 MsoTextOrientation 常量之一: |
| msoTextOrientationDownward |
| msoTextOrientationHorizontal |
| msoTextOrientationHorizontalRotatedFarEast |
| msoTextOrientationMixed |
| msoTextOrientationUpward |
| msoTextOrientationVertical |
| msoTextOrientationVerticalFarEast |
| 由于选择或安装的语言支持不同,例如,英语(美国),有些常量可能无法使用。 |
Left Single 类型,必需。标签左边缘相对于锁定标记的位置,以磅为单位。
Top Single 类型,必需。标签上边缘相对于锁定标记的位置,以磅为单位。
Width Single 类型,必需。标签的宽度,以磅为单位。
Height Single 类型,必需。标签的高度,以磅为单位。
Anchor Variant 类型,可选。指定一个 Range 对象,该对象代表与标签绑定的文本。如果指定了 Anchor,则锁定标记位于锁定区域中第一段的段首。如果忽略此参数,将自动选定锁定区域,而标签将相对于页面的上边缘和左边缘进行定位。
本示例在活动文档的新画布上添加一个蓝色的文本标签,该标签带有文字“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 SetshpLabel = 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 WithshpLabel 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
本示例在新文档中添加一个包含文本“Test Label”的标签。
Sub NewTextLabel()
Dim docNew As Document
Dim shpLabel As Shape
Set docNew = Documents.Add
'Add label to new document
Set shpLabel = docNew.Shapes _
.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=300, Height:=200)
'Add text to the label
shpLabel.TextFrame.TextRange = "Test Label"
End Sub