在 Excel VBA 中按名称单独访问组中的形状
Access Shapes in a group individually BY NAME in Excel VBA
我手动对 excel 中的一些项目进行了分组,这样我就可以更轻松地进行一些设置。
此外,我认为在 VBA 中有些事情会更容易,但我还需要使用它们的名称遍历组中的所有这些形状,因为在使用索引进行分组后将无法使用,因为它们不符合所需的顺序。
我使用了以下东西:
'Does not work
Sheet1.Shapes("Group1").GroupItems("Shape1").Top
'Works but not the wanted solution as they are unsorted.
Sheet1.Shapes("Group1").GroupItems(1).Top
有没有办法单独访问组中的形状按名称?
这样也可以,不确定能不能直接访问name
Sub x()
Dim s1 As Shape
Dim s2 As Shape
For Each s1 In ActiveSheet.Shapes
If s1.Type = msoGroup Then
For Each s2 In s1.GroupItems
If s2.Name = "Shape1" Then MsgBox s2.Top
Next s2
End If
Next s1
End Sub
我手动对 excel 中的一些项目进行了分组,这样我就可以更轻松地进行一些设置。 此外,我认为在 VBA 中有些事情会更容易,但我还需要使用它们的名称遍历组中的所有这些形状,因为在使用索引进行分组后将无法使用,因为它们不符合所需的顺序。
我使用了以下东西:
'Does not work
Sheet1.Shapes("Group1").GroupItems("Shape1").Top
'Works but not the wanted solution as they are unsorted.
Sheet1.Shapes("Group1").GroupItems(1).Top
有没有办法单独访问组中的形状按名称?
这样也可以,不确定能不能直接访问name
Sub x()
Dim s1 As Shape
Dim s2 As Shape
For Each s1 In ActiveSheet.Shapes
If s1.Type = msoGroup Then
For Each s2 In s1.GroupItems
If s2.Name = "Shape1" Then MsgBox s2.Top
Next s2
End If
Next s1
End Sub