Name

shapes.AddPolyline(SafeArrayOfPoints)

Synopsis

Draws a segmented line from an array of coordinate pairs and returns the line’s Shape object.

Argument

Settings

SafeArrayOfPoints

The 2-D array of points containing the vertices of the line

Use the Line property to set the style and formatting used for the line. The following code draws a Z-shaped line that starts at (80,100) and ends at (110,30):

Sub DrawZ( )
    Dim s As Shape, pts( ) As Single
    ' Array of points.
    ReDim pts(3, 1)
    pts(0, 0) = 80
    pts(0, 1) = 100
    pts(1, 0) = 200
    pts(1, 1) = 150
    pts(2, 0) = 15
    pts(2, 1) = 20
    pts(3, 0) = 110
    pts(3, 1) = 30
    ' Draw a curve
    Set s = ActiveSheet.Shapes.AddPolyline(pts)
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.