Delete Named Shapes/Objects via Excel VBA

NinaE_11

New Member
Joined
Aug 18, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hello!

I'm looking to delete specific named objects and shapes in an existing PowerPoint presentation via VBA in Excel. I have identified each shape by a name, however, I cannot figure out how to utilize the exact name in VBA language that will clear the contents of these shapes. I do not need to loop through each slide in PPT; I would prefer to write code to go to a specific slide, select the shape and then delete it using the assigned name. However, all I can find online is how to loop through an entire presentation - yet, I can't even get that to work. I want to delete one named shape - how do I get this to work?

Please see simple code below - any guidance is much appreciated, thank you!

Sub ClearContents()

Dim papp As PowerPoint.Application
Dim ppt As PowerPoint.Presentation

Dim shp As Shape
Dim sld As slide

Set papp = New PowerPoint.Application
Set ppt = papp.Presentations.Open ("Path")

papp.Activate

papp.ActiveWindow.View.GotoSlide (3)
sld(3).shp("NINA").delete

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,630
Try the following...

VBA Code:
Sub ClearContents()

    Dim papp As PowerPoint.Application
    Dim ppt As PowerPoint.Presentation
    Dim sld As PowerPoint.Slide
    Dim shp As PowerPoint.Shape
   
    Set papp = New PowerPoint.Application
    Set ppt = papp.Presentations.Open("Path")
    Set sld = ppt.Slides(3)
    Set shp = sld.Shapes("NINA")
   
    shp.Delete

End Sub

And, of course, if you really want to go to that particular slide, you can add...

Code:
papp.ActiveWindow.View.GotoSlide 3

Or, since you've assigned that slide to sld...

Code:
papp.ActiveWindow.View.GotoSlide sld.SlideIndex

Hope this helps!
 
Solution

NinaE_11

New Member
Joined
Aug 18, 2020
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Try the following...

VBA Code:
Sub ClearContents()

    Dim papp As PowerPoint.Application
    Dim ppt As PowerPoint.Presentation
    Dim sld As PowerPoint.Slide
    Dim shp As PowerPoint.Shape
  
    Set papp = New PowerPoint.Application
    Set ppt = papp.Presentations.Open("Path")
    Set sld = ppt.Slides(3)
    Set shp = sld.Shapes("NINA")
  
    shp.Delete

End Sub

And, of course, if you really want to go to that particular slide, you can add...

Code:
papp.ActiveWindow.View.GotoSlide 3

Or, since you've assigned that slide to sld...

Code:
papp.ActiveWindow.View.GotoSlide sld.SlideIndex

Hope this helps!
Wow, thank you very much! Worked perfectly, and thank you for the speedy response.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,271
Messages
5,657,764
Members
418,411
Latest member
Excellency

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top