문제

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)
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top