Excel 2013 Add a connector between arbitrary points on two different groups

I work in Excel 2013 to (programmatically) add a line connector between the bottom right corner of a rectangle that is part of a grouped shape with the end point of a grouped series of line segments. Be that as it may, I can't even do it manually on an Excel worksheet that contains these shapes.

The problems include:

  • Only the middle on the desired rectangle will accept the connector.
  • A grouped series of line segments does not even show a “connection point” for the end end of a straight line connector.

Here is an image of what I'm trying to do:

[I do not have 10 "reputation points", so I can’t post a photo of what I'm trying to do. Not a particularly useful feature! How to get reputation points in this game?]

I was able to create and name two groups and thought that I would work with them to add a connector, but this is not so.

Here is the code I worked with:

Sub create_new_profile()
    Dim firstRect As Shape
    Dim firstLine As Shape
    Set myDocument = Worksheets(1)
    Set s = myDocument.Shapes
'    Set firstRect = s.Range("shpNewGarage")
'    Set firstLine = s.Range("shpProfile")
    Dim Shp As Shape
'    For Each Shp In myDocument.Shapes
    For Each Shp In s
        If Shp.Name = "shpNewGarage" Then
            Set firstRect = Shp
    Else
    End If
    Next Shp
'    For Each Shp In myDocument.Shapes
    For Each Shp In s
        If Shp.Name = "shpProfile" Then
            Set firstLine = Shp
    Else
    End If
    Next Shp
    firstRect.Select 'this works
    firstLine.Select 'this works
'    Set firstRect = s.AddShape(msoShapeRectangle, 100, 50, 200, 100)
'    Set firstLine = s.AddShape(msoShapeRectangle, 300, 300, 200, 100)
'    Set firstRect = ActiveSheet.Shapes.Range("shpNewGarage")
'    Set firstLine = ActiveSheet.Shapes.Range("shpProfile")
    Dim c As Shape
    Set c = s.AddConnector(msoConnectorStraight, 0, 0, 100, 100)
'    On Error Resume Next
    With c.ConnectorFormat
      **.BeginConnect ConnectedShape:=firstRect, ConnectionSite:=1**
      .EndConnect ConnectedShape:=firstLine, ConnectionSite:=1
'     .BeginConnect ConnectedShape:="shpNewGarage", ConnectionSite:=1
'     .EndConnect ConnectedShape:="shpProfile", ConnectionSite:=1
'     .BeginConnect ConnectedShape:=ActiveSheet.Shapes.Range("shpNewGarage"), ConnectionSite:=1
'     .EndConnect ConnectedShape:=ActiveSheet.Shapes.Range("shpProfile"), ConnectionSite:=1
     c.RerouteConnections
    End With
End Sub

This particular version of the code ends with a runtime error on the line following the line:

With c.ConnectorFormat

Here is the error message:

[I do not have 10 "reputation points", so I can not post the image of the error message that I receive. Again, how do I get reputation points?]

Any direction to help me accomplish this task programmatically would be very helpful.

Thanks for explaining that now I can send images. This should help.

, :

New garage, existing driveway profile and new profile (red.)

(firstRect, "shpNewGarage" ) , . (firstLine, "shpProfile" ) ( /) ( ). , ( ) (), , , , , , ( ) .

, :

VBA error message.

, , .

, / . Stackoverflow , , .

+4
1

,

, , , , :

.BeginConnect ConnectedShape: = firstRect, ConnectionSite: = 1

ConnectionSite: " , ConnectedShape. 1 , ConnectionSiteCount "

, firstRect Node: , ,

- , (generic): " AddNodes FreeformBuilder , ConvertToShape", ()

. , , .

, , , , , . :

Option Explicit

Sub create_new_profile()

    Dim ws As Worksheet

    Dim shp1 As Shape
    Dim shp2 As Shape

    Dim line1 As Shape
    Dim line2 As Shape

    Set ws = Sheet1

    With ws.Shapes

        'AddShape:        Left=10, Top=10, Width=50, Height=30
        Set shp1 = .AddShape(msoShapeRectangle, 10, 10, 50, 30)
        Set shp2 = .AddShape(msoShapeRectangle, 70, 50, 50, 30)

        'AddConnector:          BeginX=60, BeginY=10, EndX=120, EndY=50
        Set line1 = .AddConnector(msoConnectorStraight, 60, 10, 120, 50)
        Set line2 = .AddConnector(msoConnectorStraight, 60, 40, 120, 80)
    End With

    line1.Line.ForeColor.RGB = RGB(255, 0, 0)   'Color Red
    line2.Line.ForeColor.RGB = RGB(255, 0, 0)

End Sub

:

connected shapes

.

, , (msoEditingCorner), node node

() , VBA , - " ":

enter image description here

,

+1

All Articles