AddLabel Method

Microsoft Word Visual Basic

Show All

AddLabel Method

       

AddLabel method as it applies to the CanvasShapes object.

Adds a text label to a drawing canvas. Returns a Shape object that represents the drawing canvas and adds it to the CanvasShapes collection.

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

expression   Required. An expression that returns a CanvasShapes object.

Orientation   Required MsoTextOrientation. The orientation of the text.

MsoTextOrientation can be one of the following MsoTextOrientation constants:
msoTextOrientationDownward
msoTextOrientationHorizontal
msoTextOrientationHorizontalRotatedFarEast
msoTextOrientationMixed
msoTextOrientationUpward
msoTextOrientationVertical
msoTextOrientationVerticalFarEast
Some of these constants may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.

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.

AddLabel method as it applies to the Shapes object.

Adds a text label to a document. Returns a Shape object that represents the text label and adds it to the Shapes collection.

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

expression   Required. An expression that returns a Shapes object.

Orientation   Required MsoTextOrientation. The orientation of the text.

MsoTextOrientation can be one of the following MsoTextOrientation constants:
msoTextOrientationDownward
msoTextOrientationHorizontal
msoTextOrientationHorizontalRotatedFarEast
msoTextOrientationMixed
msoTextOrientationUpward
msoTextOrientationVertical
msoTextOrientationVerticalFarEast
Some of these constants may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.

Left   Required Single. The position, measured in points, of the left edge of the label relative to the anchor.

Top   Required Single. The position, measured in points, of the top edge of the label relative to the anchor.

Width   Required Single. The width of the label, in points.

Height   Required Single. The height of the label, in points.

Anchor   Optional Variant. A Range object that represents the text to which the label is bound. If Anchor is specified, the anchor is positioned at the beginning of the first paragraph in the anchoring range. If this argument is omitted, the anchoring range is selected automatically and the label is positioned relative to the top and left edges of the page.

Example

As it applies to the CanvasShapes object.

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

As it applies to the Shapes object.

This example adds a label that contains the text "Test Label" to a new document.

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