Try the code bellow in a modeless form.
Option Explicit
Private WithEvents vPages As Visio.Pages
Private startTime As Date
Private bNewShape As Boolean
Private bConnsDel As Boolean
Private bConnsAdded As Boolean
Private oldConn As Shape
Private newConn As Shape
Private newShp As Shape
Private Sub UserForm_Initialize()
Set vPages = ActiveDocument.Pages
End Sub
Private Sub vPages_ConnectionsAdded(ByVal Connects As IVConnects)
Dim conn As Connect
If Now - startTime < 2 And bConnsDel Then
Debug.Print "Now we can do stuff with"
Debug.Print "New shape: ", newShp.Name
Debug.Print "New connector: ", newConn.Name
Debug.Print "Old connector: ", oldConn.Name
End If
'Reset'
bConnsAdded = False
bNewShape = False
bConnsDel = False
startTime = 0
Set oldConn = Nothing
Set newConn = Nothing
Set newShp = Nothing
End Sub
Private Sub vPages_ConnectionsDeleted(ByVal Connects As IVConnects)
Dim conn As Connect
If Now - startTime < 1 And bNewShape Then
bConnsDel = True
Debug.Print "Conns deleted"
For Each conn In Connects
Debug.Print "conn deleted from sheet"; conn.FromSheet.Name
Debug.Print "conn deleted to sheet"; conn.ToSheet.Name
Set oldConn = conn.FromSheet
Next conn
Else
'Reset'
bNewShape = False
bConnsDel = False
startTime = 0
Set oldConn = Nothing
Set newConn = Nothing
Set newShp = Nothing
End If
End Sub
Private Sub vPages_ShapeAdded(ByVal Shape As IVShape)
startTime = Now
bNewShape = True
If Shape.OneD Then
Set newConn = Shape
Else
Set newShp = Shape
End If
End Sub
I thought that it would be important to differentiate between a real split and manual operations.
So I catch the different events shapeAdded (twice - one for the shape the second for the connector), connections deleted and connections added.
Plus I set a timer so as to make sure this happens in a time shorter than done manually.
Only if all the flags are set to true and the time is less than a hard coded value (here 2), then do stuff.
Otherwise do nothing. Reset the variables in both cases.
Really cumbersome and complicated, MS should have given a dedicated event.