VBA Remove all images from a PPT slide
RodyRody
Posted messages
48
Status
Member
-
RodyRody Posted messages 48 Status Member -
RodyRody Posted messages 48 Status Member -
Hello forum,
Is there a VBA code to delete all images from a PPT slide using Excel?
I don't want to use an absolute reference like
Dim Pptdoc As Powerpoint.Presentation
Pptdoc.Slides(6).Shapes("Picture 9").Delete
because the name of my picture will vary every month. This month it's (Picture 9) but next month it will be ("Picture X")
Thank you in advance for your help
R
Is there a VBA code to delete all images from a PPT slide using Excel?
I don't want to use an absolute reference like
Dim Pptdoc As Powerpoint.Presentation
Pptdoc.Slides(6).Shapes("Picture 9").Delete
because the name of my picture will vary every month. This month it's (Picture 9) but next month it will be ("Picture X")
Thank you in advance for your help
R
3 answers
-
Hello,
There isn't just ONE code... VBA is a programming language, so it needs to be written.
And to know how to write it, one must be precise about what they want.
You talk about images to delete (shapes).
But Shapes encompasses pretty much everything we want: images, drawings, autoshapes, headers, footers, an Excel table, etc.
So yes, we can delete all the "shapes" from the slide... But in that case, we might as well replace the slide with a blank one!!
Now we can possibly filter based on the shape to be deleted.
m@rina
--
If you want to be helped effectively, make sure you are on the right forum,... and specify the software used as well as its version. We are not fortune-tellers! -
Hello Marina,
Thank you for your response. I'm sorry, I will try to be more precise.
I am looking to automate a PPT presentation that updates every month based on an Excel file. I can't work with links between Excel and PPT because they weigh down the presentation too much. The idea is to go through VBA. Once the xls file is updated, I press a button that runs a macro which:
1) Opens the PPT
2) Deletes the old tables
3) Pastes the new tables using enhanced metafile special paste.
4) Saves, then closes the new PPT.
My problem lies with point number 2. Indeed, for now I am using an absolute reference. Here is the beginning of my codeDim PPT As Powerpoint.Application Dim Pptdoc As Powerpoint.Presentation Dim nbshpe As Byte Set PPT = CreateObject("Powerpoint.Application") PPT.Visible = True
1) => Opens the file
Set Pptdoc = _
PPT.Presentations.Open("U:\Prive\Finance Team\Rodrigo\Automatisation des présentations\PEMJP_pres\Rapport Mensuel_04-2012.ppt")
2) => Deletes the old tables
ptdoc.Slides(6).Shapes("Picture 9").Delete
3) => Pastes the new tables using enhanced metafile special paste.
Sheets("ITC_Periodic").Range("A13:BR32").Copy
Pptdoc.Slides(6).Shapes.PasteSpecial ppPasteEnhancedMetafile
The issue is that once the macro has deleted Picture 9 and pasted the table, its PPT name changes to Picture 10.
I wanted to work around the problem by writing a line of code that asks PPT to delete all the images on slide 6 so that I don't have to modify the code with each update.
If I delete the slide and replace it with a blank one, I would have to rewrite the title.
I hope I have clarified my problem.
What do you think?
Thanks in advance to everyone. -
Good evening,
The simplest thing is to always give the same name to the table.
To do this, after pasting, we will take the last object and give it the chosen name.
Thus, in the macro, it will suffice to delete the object of this name and rename it with the same name, which would give:
dim tablo As Shape, nb 'deletion of the table On Error Resume Next 'in case the tablo does not exist Set tablo=Pptdoc.Slides(6).Shapes("tablo") tablo.Delete On Error Goto 0 'we paste the table Pptdoc.Slides(6).Shapes.PasteSpecial ppPasteEnhancedMetafile 'we count the nb of shapes nb = Pptdoc.Slides(6).Shapes.Count 'we give the name tablo to the last one: Pptdoc.Slides(6).Shapes(nb).Name = "tablo"
m@rina
--
If you want to be helped effectively, make sure you are on the right forum,... and specify the software used as well as its version. We lack fortune tellers!