获取形状内的形状组名称

时间:2015-09-03 23:41:57

标签: excel vba

当我遍历" Full_Banner" 的GroupItem时,我的代码会在红色方块中返回下面每个项目的名称。

enter image description here

我想要的是我的代码返回蓝色方块中每个项目的名称(见下文)。我怎么能这样做呢?

enter image description here

Sub Get_Shape_Name()

For Each element In ActiveSheet.Shapes("Full_Banner").GroupItems

    MsgBox element.Name

Next

End Sub

1 个答案:

答案 0 :(得分:2)

我不知道任何访问子组名称的方法。作为解决方法,您可以取消组合形状,列出所有组项并将形状分组:

Sub Get_Shape_Name()

    Dim aShape As Shape
    Dim rShape As ShapeRange

    Const sName As String = "Full_Banner"

    Set rShape = ActiveSheet.Shapes(sName).Ungroup
      For Each aShape In rShape
        If aShape.ShapeStyle = msoShapeMixed Then
          MsgBox aShape.Name
        End If
      Next
    rShape.Group.Name = sName

End Sub