似乎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」都是錯誤的,並且對整個組進行報告。 –