如果你知道它是Id
,有没有办法获得形状Name
?
例如,如果我有这个:
Dim myshape As Shape
myshape.Name
我可以得到它Id
吗?
myshape.Id = getIdByName(myshape.Name)
答案 0 :(得分:4)
当然,这很简单:
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
这适用于您指定的幻灯片。您也可以循环浏览所有幻灯片,但请注意,可能有多个具有相同名称的形状,因此您必须找出所需的形状。