VBA从“形状”和“塑造”获得连接器

时间:2011-07-11 13:52:16

标签: vba

我在Excel中有一个流程设计(使用形状,连接器等)。 我需要的是拥有一个矩阵,并且每个形状都包含所有前辈和所有后继者。 在VBA中,要做到这一点,我正在尝试做类似的事情: - 我列出了所有连接器(Shapes.AutoShapeType = -2) - 对于每一个我想要的形状'from'的名称和形状'to'的名称。

我希望你明白这个主意。 我没有找到连接器的属性来检索此信息。

这是我到目前为止所做的:

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

有没有人知道有这些信息的形状参数?

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

您可以使用类似的东西:

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