Skip to main content

ConnectorFormat object

Table of contents
  1. Remarks
  2. Example

Contains properties and methods that apply to connectors.


A connector is a line that attaches two other shapes at points called connection sites. If you rearrange shapes that are connected, the geometry of the connector will be automatically adjusted so that the shapes remain connected.

Connection sites are generally numbered according to the rules presented in the following table.

Shape type Connection site numbering scheme
AutoShapes, WordArt, pictures, and OLE objects The connection sites are numbered starting at the top and proceeding counterclockwise.
Freeforms The connection sites are the vertices, and they correspond to the vertex numbers.

Use the ConnectorFormat property of the Shape object to return a ConnectorFormat object. Use the BeginConnect and EndConnect methods to attach the ends of the connector to other shapes in the document. Use the RerouteConnections method of the Shape object to automatically find the shortest path between the two shapes connected by the connector. Use the Connector property to see whether a shape is a connector.


To figure out which number corresponds to which connection site on a complex shape, you can experiment with the shape while the macro recorder is turned on and then examine the recorded code; or you can create a shape, select it, and then run the following example. This code will number each connection site and attach a connector to it.

Set mainshape = ActiveWindow.Selection.ShapeRange(1)
With mainshape
    bx = .Left + .Width + 50
    by = .Top + .Height + 50
End With
With ActiveSheet
    For j = 1 To mainshape.ConnectionSiteCount
        With .Shapes.AddConnector(msoConnectorStraight, bx, by, bx + 50, by + 50)
            .ConnectorFormat.EndConnect mainshape, j
            .ConnectorFormat.Type = msoConnectorElbow
            .Line.ForeColor.RGB = RGB(255, 0, 0)
            l = .Left
            t = .Top
        End With
        With .Shapes.AddTextbox(msoTextOrientationHorizontal, l, t, 36, 14)
            .Fill.Visible = False
            .Line.Visible = False
            .TextFrame.Characters.Text = j
        End With
    Next j
End With

The following example adds two rectangles to myDocument and connects them with a curved connector.

Set myDocument = Worksheets(1)
Set s = myDocument.Shapes
Set firstRect = s.AddShape(msoShapeRectangle, 100, 50, 200, 100)
Set secondRect = s.AddShape(msoShapeRectangle, 300, 300, 200, 100)
Set c = s.AddConnector(msoConnectorCurve, 0, 0, 0, 0)
With c.ConnectorFormat
    .BeginConnect ConnectedShape:=firstRect, ConnectionSite:=1
    .EndConnect ConnectedShape:=secondRect, ConnectionSite:=1
End With

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>