Hi Skip!
Yep, still at it. Following on from the other night, it occurred to me that it was rather silly to try and duplicate a command that was already available in Excel (ie the straight connector).
No sooner did I think I had it sorted, when I ran into other problems. Check the code:
____________________________________________________________
Private Sub Task4_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 And CurType = 3 Then
CommandBars.FindControl(ID:=2640).Execute 'Invoke Straight Connector
Call Connect
End If
End Sub
____________________________________________________________
Private Sub Connect()
Set ws = Worksheets("Sheet1")
'Find temporary connector and set variables to indicate which tasks are being connected
For Each sh In Shapes
If sh.Connector = True Then
If sh.ConnectorFormat.Type = msoConnectorStraight Then
sh.Name = "TempConnector"
Set FirstBar = sh.ConnectorFormat.BeginConnectedShape
Set SecondBar = sh.ConnectorFormat.EndConnectedShape
End If
End If
Next sh
'Delete the temporary connector if it exists
ws.Shapes("TempConnector").Delete
'Set connection name
ConnName = FirstBar.Name & "conn" & SecondBar.Name
'Add new connector and set properties
With ws.Shapes.AddConnector(msoConnectorElbow, 10, 10, 10, 10)
.Name = ConnName
.Line.EndArrowheadStyle = msoArrowheadTriangle
.Line.EndArrowheadLength = msoArrowheadShort
.Line.EndArrowheadWidth = msoArrowheadNarrow
.OnAction = "EditConnectorMenu"
End With
'Set connector formats
With ws.Shapes(ConnName).ConnectorFormat
.BeginConnect FirstBar, ConnectionSite:=4
.EndConnect SecondBar, ConnectionSite:=2
End With
End Sub
The problem is that after the connector command is invoked, the code goes straight to the Call Connect routine and of course the straight connector that it tests for does not exist yet, causing an error.
I’m not sure how to “suspend” further code execution to allow the connector call to be completed first. Any ideas?