按名称获取形状 ID [英] Get shape Id by Name

查看:58
本文介绍了按名称获取形状 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你知道形状的 Id,有什么办法可以得到它的 Name 吗?

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

例如,如果我有这个:

Dim myshape As Shape
myshape.Name

我能得到它的Id吗?

myshape.Id = getIdByName(myshape.Name)

推荐答案

当然,这很直接:

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.

这篇关于按名称获取形状 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆