Hi Chirag,
Thank you very much, this works great.
I have converted your function to allow for groups, however, I have not
managed to find a simple why to determine if a shape exists without raising
an error.
Is there a simple way to determine that and object is Nothing?
The following works, but is there a better way:
Function FindShapeById(ByVal Shps As Shapes, ByVal Id As Long) As Shape
Dim Shp As Shape
Dim testShapeName As String
On Error Resume Next
For Each Shp In Shps
If Shp.Id = Id Then
Set FindShapeById = Shp
Exit For
End If
If Shp.Type = msoGroup Then
Set FindShapeById = FindGroupShapeById(Shp, Id)
testShapeName = FindShapeById.Name
If Err.Number = 0 Then
Exit For
End If
End If
Next
End Function
Function FindGroupShapeById(ByVal GrpShp As Shape, ByVal Id As Long) As
Shape
Dim Shp As Shape
Dim testShapeName As String
On Error Resume Next
gCnt = GrpShp.GroupItems.Count
For gNum = 1 To gCnt
Set Shp = GrpShp.GroupItems.Item(gNum)
If Shp.Id = Id Then
Set FindGroupShapeById = Shp
Exit For
End If
If Shp.Type = msoGroup Then
Set FindGroupShapeById = FindGroupShapeById(Shp, Id)
testShapeName = FindGroupShapeById.Name
If Err.Number = 0 Then
Exit For
End If
End If
Next
End Function
Thanks again for your help.
Regards, Peter