AddLine Method

Applies To

Shapes collection object.

Description

Creates a line. Returns a Shape object that represents the new line.

Syntax

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

expression Required. An expression that returns a Shapes collection.

BeginX, BeginY Required Single. The position (in points) of the line's starting point, relative to the anchor.

EndX, EndY Required Single. The position (in points) of the line's end point, relative to the anchor.

Anchor Optional Variant. A Range object that represents the text that the line is bound to. 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 line 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.

See Also

AddPolyline method, LineFormat object.

Example

This example adds a dashed, green line to a new document.

Set myDocument = Documents.Add
Set myLine = myDocument.Shapes.AddLine(100, 100, 60, 20)
With myLine.Line
    .DashStyle = msoLineDash
    .ForeColor.RGB = RGB(0, 128, 0)
End With
This example adds a line to the active document and then formats the line as a red arrow.

Set myLine = ActiveDocument.Shapes.AddLine(100, 100, 60, 20)
With myLine.Line
    .BeginArrowheadStyle = msoArrowheadNone
    .EndArrowheadStyle = msoArrowheadTriangle
    .ForeColor.RGB = RGB(128, 0, 0)
End With