似乎GroupItems
TopLeftCell
和BottomRightCell
中的项目是错误的,并报告整个组。
对比属性Top
和Left
正确报告GroupItems
集合中的项目。
作为一个变通办法可以这样考虑:
Sub Demo()
Dim ws As Worksheet
Dim grp As Shape
Dim shp As Shape, s As Shape
Set ws = ActiveSheet
Set grp = ws.Shapes("Group 1") '<~~ update to suit
With grp
For Each shp In .GroupItems
' Create a temporary duplicate shape
Set s = ws.Shapes.AddShape(msoShapeRectangle, shp.Left, shp.Top, shp.Width, shp.Height)
' Report the grouped shape to contrast the temporary shape result below
Debug.Print shp.TopLeftCell.Row, shp.BottomRightCell.Row
' Report the duplicate shape to see correct location
Debug.Print s.TopLeftCell.Row, s.BottomRightCell.Row
' Delete temporary shape
s.Delete
Next
End With
End Sub
在这里,我创建的每个形状在GroupItems
集合重复组外,并报告其单元位置。然后删除重复。
我用矩形来证明,但其他形状类型应该是相似的
不知道,但我认为这是可能你可能需要取消组合形状,得到你想要的,然后重新组合形状。 –
从逻辑上讲,你所要求的不应该是可能的。 Excel的手册说,分组使得形状“被视为一个单一的对象”。因此,分组形状应该已经失去与工作表的个人关系。为什么你要在确保他们像一个团体一样行动后个别地移动他们? – Variatus
@Variatus恕我直言,OP要求什么_应该是可能的。 Excel提供了“GroupItems”集合来访问组中的各个形状。对于“GroupItems”属性中的每个项目“Top”和“Left”报告都是正确的,并且可以修改以移动各个组项目。似乎对于GroupItems中的项目,“TopLeftCell”和“BottomRightCell”都是错误的,并且对整个组进行报告。 –