AddLine Method

Shapes.AddLine Method (Word)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Adds a line to a drawing canvas.

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

expression Required. A variable that represents a Shapes collection.

Parameters

Name

Required/Optional

Data Type

Description

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 endpoint, relative to the drawing canvas.

EndY

Required

Single

The vertical position, measured in points, of the line's endpoint, relative to the drawing canvas.

Return Value

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

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
Show:
© 2016 Microsoft