Home Products Customers Tips VBA OfficeOne on Mac Contact us

FindShapeById

Microsoft PowerPoint 2002 introduced Id for shapes. It doesn't have any direct way of finding a shape by Id on a slide. The FindShapeById() function here provides that. Specify the shapes that you want it to search in. This could be GroupShapes collection (GroupItems property of a Shape object) or Shapes collection (Shapes property of a Slide object).

The function may not find any shape with the specified Id. In that case, it will return Nothing as the function result.

Function FindShapeById(ByVal Shps As Object, ByVal Id As Long) As Shape
    Dim I As Long

    For I = 1 To Shps.Count
        If Shps(I).Id = Id Then
            Set FindShapeById = Shps(I)
            Exit For
        End If

        If Shps(I).Type = msoGroup Then
            Set FindShapeById = FindShapeById(Shps(I).GroupItems, Id)
            If Not (FindShapeById Is Nothing) Then
                Exit For
            End If
        End If
    Next
End Function

The following code snippet shows how to call FindShapeById() function.

Sub Test()
    MsgBox FindShapeById(ActivePresentation.Slides(1).Shapes, 2050).Name
End Sub


Home | Products | Tips | VBA | FAQ | Utilities | Disclaimer | Privacy Policy | Mac | Links | Contact us

Contact OfficeOne on email at officeone@officeoneonline.com. Copyright © 2001-2017 OfficeOne. All rights reserved.

page counter