2011-03-28 149 views
3

如果您知道它是Name,有沒有辦法獲得圖形的Id通過名稱獲取圖形ID

舉例來說,如果我有這樣的:

Dim myshape As Shape 
myshape.Name 

我可以得到它的Id

myshape.Id = getIdByName(myshape.Name) 

回答

4

當然,這是相當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 

這適用於您指定的幻燈片。您也可以遍歷所有幻燈片,但請注意,可能會有多個形狀具有相同的名稱,因此您必須確定要使用哪一個。

+0

我不是VB'er,所以對我來說並不那麼簡單。 :) – 2011-03-28 22:14:50

+0

@muntoo:沒問題,我在這裏幫忙:) – 2011-03-28 22:16:01