开发者

Get shape Id by Name

Is there any way to get a shape's Id if you know it's Na开发者_如何学Gome?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜