VBA get connector 'from shape' and 'to shape'
I have a flow design in Excel (using shapes, connectors, etc). What I need is to have a matrix and for every shape to have all the predecessors and all the successors. In VBA, to do that I'm trying to do something like: - I'm listing all the connectors (Shapes.AutoShapeType = -2) - for each one I want to have the name of the shape 'from' and the name of the shape 'to'.
I hope you get the idea. I don't find the properties of the connector in order to retrieve this info.
This is what I have so far:
Sub getTransitions()
''the sheet with the design
Set designSheet = Sheets("DesignSheet")
Set tempSheet = Sheets("temp") 'Sheets.Add
lLoop = 0
'Loop through all shapes on active sheet
For开发者_高级运维 Each sShapes In designSheet.Shapes
'Increment Variable lLoop for row numbers
With sShapes
''connector shape type
If ((sShapes.AutoShapeType) = -2) Then
lLoop = lLoop + 1
tempSheet.Cells(lLoop + 1, 1) = sShapes.Name
tempSheet.Cells(lLoop + 1, 2) = sShapes.AutoShapeType
''here I want to have for the sShapes the from shape and the to shape
End If
End With
Next sShapes
End Sub
Does anyone know the shape parameters for having this info ?
It seems that utilizing the ConnectorFormat
object returned by the ConnectorFormat
property and looking into the BeginConnectedShape
and EndConnectedShape
properties may be your best bet.
You can use something like that:
Set g = ActiveSheet
i = 1
For Each s In g.Shapes
If ((s.AutoShapeType) <> -2) Then 'all shapes without connectors
c = 0
For Each s1 In g.Shapes
If ((s1.AutoShapeType) = -2) Then 'only connectors
With s1.ConnectorFormat
Set a = .BeginConnectedShape
Set b = .EndConnectedShape
End With
If a.Name = s.Name Or b.Name = s.Name Then
c = c + 1
End If
End If
Next s1
g.Cells(i, "A").Value = s.Name 'name of shape
g.Cells(i, "B").Value = c 'count of connectors
i = i + 1
End If
Next s
精彩评论