AddLine Method

Microsoft Word Visual Basic

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

expression.AddLine(BeginX, BeginY, EndX, EndY)

expression    Required. An expression that returns a CanvasShapes object.

BeginX   Required Single. The horizontal position, measured in points, of the line's starting point, relative to the drawing canvas.

BeginY   Required Single. The vertical position, measured in points, of the line's starting point, relative to the drawing canvas.

EndX   Required Single. The horizontal position, measured in points, of the line's end point, relative to the drawing canvas.

EndY   Required Single. The vertical position, measured in points, of the line's end point, relative to the drawing canvas.

ShowAddLine method as it applies to the Shapes object.

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

expression.AddLine(BeginX, BeginY, EndX, EndY, Anchor)

expression    Required. An expression that returns a Shapes object.

BeginX   Required Single. The horizontal position, measured in points, of the line's starting point, relative to the anchor.

BeginY   Required Single. The vertical position, measured in points, of the line's starting point, relative to the anchor.

EndX   Required Single. The horizontal position, measured in points, of the line's end point, relative to the anchor.

EndY   Required Single. The vertical position, measured in points, of the line's end point, relative to the anchor.

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.

Remarks

To create an arrow, use the Line property to format a line.

Example

ShowAs it applies to the CanvasShapes object.

This example adds a purple line with an arrow to a new drawing canvas.

Sub NewCanvasLine()
    Dim shpCanvas As Shape
    Dim shpLine As Shape

    'Add new drawing canvas to the active document
    Set shpCanvas = ActiveDocument.Shapes _
        .AddCanvas(Left:=100, Top:=75, _
        Width:=150, Height:=200)

    'Add a line to the drawing canvas
    Set shpLine = shpCanvas.CanvasItems.AddLine( _
        BeginX:=25, BeginY:=25, EndX:=150, EndY:=150)

    'Add an arrow to the line and sets the color to purple
    With shpLine.Line
        .BeginArrowheadStyle = msoArrowheadDiamond
        .BeginArrowheadWidth = msoArrowheadWide
        .ForeColor.RGB = RGB(Red:=150, Green:=0, Blue:=255)
    End With
End Sub
				

ShowAs it applies to the Shapes object.

This example adds a line to the active document and then formats the line as a red arrow.

Sub NewLine()
    Dim lineNew As Shape

    'Add new line to document
    Set lineNew = ActiveDocument.Shapes.AddLine_
        (Left:=100, Top:=100, Width:=60, Height:=20)

    'Format line
    With lineNew.Line
        .BeginArrowheadStyle = msoArrowheadNone
        .EndArrowheadStyle = msoArrowheadTriangle
        .ForeColor.RGB = RGB(Red:=128, Green:=0, Blue:=0)
    End With
End Sub