View Single Post
 
Old 04-14-2012, 12:12 AM
JohnWilson JohnWilson is offline Windows 7 64bit Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

PowerPoint vba doesn't really offer a convenient way to use ID like that.

The best solution is to write a custom function

Code:
Function ShapeByID(ThisSlide As Slide, ThisID As Long) As Shape
For Each ShapeByID In ThisSlide.Shapes
If ShapeByID.Id = ThisID Then
Exit Function
End If
Next
End Function
And an example of how to use to delete shape with ID=8 from slide 1

Code:
Sub exampleID()
On Error Resume Next
ShapeByID(ThisSlide:=ActivePresentation.Slides(1), ThisID:=8).Delete
End Sub
An easier solution is to use the selection pane to rename using unique names then ....

Code:
Sub DeleteByName()
On Error Resume Next ' in case shape doesn't exist
ActivePresentation.Slides(1).Shapes("MyName").Delete
End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials

Last edited by JohnWilson; 04-14-2012 at 06:38 AM.
Reply With Quote