Name

connectorformat.BeginConnect(ConnectedShape, ConnectionSite)

Synopsis

Sets the first shape to connect.

Argument

Settings

ConnectedShape

The first Shape object to connect

ConnectionSite

The index of the connection site on the object

When creating a connection, it is easiest to use arbitrary values for ConnectionSite as well as the size and location of the connector and to call RerouteConnection to establish the shortest path, as shown here:

Sub CreateConnection( )
    Dim ws As Worksheet, s(1) As Shape, conn As Shape
    Set ws = ActiveSheet
    ' Draw two shapes.
    Set s(0) = ws.Shapes.AddShape(msoShapeCube, 20, 20, 40, 40)
    Set s(1) = ws.Shapes.AddShape(msoShapeCan, 60, 80, 30, 40)
    ' Draw connector.
    Set conn = ws.Shapes.AddConnector(msoConnectorCurve, 1, 1, 1, 1)
    ' Establish connection.
    conn.ConnectorFormat.BeginConnect s(0), 1
    conn.ConnectorFormat.EndConnect s(1), 1
    ' Connect via the shortest path.
    conn.RerouteConnections
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.