Question

Is there any way to get a shape's Id if you know it's Name?

For example, if I have this:

Dim myshape As Shape
myshape.Name

Can I get it's Id?

myshape.Id = getIdByName(myshape.Name)
Was it helpful?

Solution

Sure, it's pretty straigtforward:

Sub PrintShapeID()
    Debug.Print getIDByName("My Shape", 1)
End Sub

Function getIDByName(shapeName As String, slide As Integer)
    Dim ap As Presentation: Set ap = ActivePresentation
    Dim sl As slide: Set sl = ap.Slides(slide)
    Dim sh As Shape: Set sh = sl.Shapes(shapeName)
    getIDByName = sh.Id
End Function

This works for the slide that you specify. You can also loop through all slides, but note that there may be more than one shape with the same name so you'd have to figure out which one you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top