Get shape Id by Name

与世无争的帅哥 提交于 2019-12-10 17:10:46

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/5465465/get-shape-id-by-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!