Partager via


CanvasShapes.AddLabel Method (Word)

Adds a text label to a drawing canvas. Returns a Shapes object that represents the text label.

Syntax

expression .AddLabel(Orientation, Left, Top, Width, Height)

expression Required. A variable that represents a CanvasShapes collection.

Parameters

Name

Required/Optional

Data Type

Description

Orientation

Required

MsoText

The orientation of the text.

Left

Required

Single

The position, measured in points, of the left edge of the label relative to the left edge of the drawing canvas.

Top

Required

Single

The position, measured in points, of the top edge of the label relative to the top edge of the drawing canvas.

Width

Required

Single

The width of the label, in points.

Height

Required

Single

The height of the label, in points.

Example

This example adds a blue text label with the text "Hello World" to a new drawing canvas in the active document.

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

See Also

Concepts

CanvasShapes Object Members

CanvasShapes Collection