![]() |
This is wierd!
Greetings
I am using Excel 2003 - I don't know how this would work in other versions. Open up a new workbook and put 2 shapes (I used ovals) on the sheet. Then group them. In a code module add: Sub disappointing() Dim myName As String Dim shp As Shape myName = Sheets(1).Shapes("Group 3").GroupItems(1).name MsgBox myName Set shp = Sheets(1).Shapes("Group 3").GroupItems(myName) MsgBox shp.name End Sub The first msgbox gives "Oval 1" as expected but the next line throws a run-time "subscript out of range" error. GroupItems is expecting an integer and can't handle a string like a full-fledged collection (such as Shapes itself) could do - disappointing design if you ask me. *But* I you now enter: Sub wierd() Dim shp As Shape For Each shp In Sheets(1).Shapes("Group 3").GroupItems shp.Select Selection.name = shp.name Next shp End Sub And run it and *then* run disappointing () - you discover that the subscript error has vanished and that both msgboxes work as hoped. What is going on here? It seems that going through Selection is needed - it somehow makes the shape names magic or something so that they cause GroupItems, against all documentation, to start acting like a collection. -semiopen |
All times are GMT +1. The time now is 02:05 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com