ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Shapes(Count) (https://www.excelbanter.com/excel-programming/403346-shapes-count.html)

Linda Edlund

Shapes(Count)
 
The code below works fine…

Dim shpGroup(10) As Shape
Dim shpTemp As Shape
Dim element
For element = 1 To 10
Set shpGroup(element) = ActiveSheet.Shapes(element)
If shpGroup(element).Type = msoGroup Then
For Each shpTemp In shpGroup(element).GroupItems
Debug.Print "index = " & element, " group " & shpGroup(element).Name,
shpTemp.Name
Next shpTemp
Else
Debug.Print "index = " & element, " shape ", , shpGroup(element).Name
End If
Next element

but statement…

For Each element In ActiveSheet.Shapes(Count) '? .Count .Index

gives error <index unavailable

Any possible reason ?

Jon Peltier

Shapes(Count)
 
I think you're getting at this:

Sub GetGroupItems()
Dim iShape As Long
Dim iElement As Long
For iShape = 1 To ActiveSheet.Shapes.Count
If ActiveSheet.Shapes(iShape).Type = msoGroup Then
For iElement = 1 To ActiveSheet.Shapes(iShape).GroupItems.Count
Debug.Print ActiveSheet.Shapes(iShape).GroupItems(iElement).Na me
Next
End If
Next
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Linda Edlund" wrote in message
7...
The code below works fine…

Dim shpGroup(10) As Shape
Dim shpTemp As Shape
Dim element
For element = 1 To 10
Set shpGroup(element) = ActiveSheet.Shapes(element)
If shpGroup(element).Type = msoGroup Then
For Each shpTemp In shpGroup(element).GroupItems
Debug.Print "index = " & element, " group " & shpGroup(element).Name,
shpTemp.Name
Next shpTemp
Else
Debug.Print "index = " & element, " shape ", , shpGroup(element).Name
End If
Next element

but statement…

For Each element In ActiveSheet.Shapes(Count) '? .Count .Index

gives error <index unavailable

Any possible reason ?




Linda Edlund

Shapes(Count)
 
Thank you for the answer Jon

It works smoothly


All times are GMT +1. The time now is 04:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com