View Full Version : [SOLVED:] Deleting pictures using code
Blueskies
07-07-2016, 02:46 AM
I have a presentation which has slides with single pictures on them and I would like a button to delete the picture on the slide while I am in the Show mode.
Any help much appreciated. Thanks, Paul
John Wilson
07-07-2016, 03:06 AM
Are you sure that's what you want? In most cases doing this with an animation is more desirable. If you delete a picture with code it is gone for good.
Blueskies
07-07-2016, 03:12 AM
Hi John
Actually just found an answer . . but thanks for your help. The reason for deletion is just so that I can insert a new picture there. Cheers.
Sub DeleteAllPictures()
Dim sldTemp As Slide
Dim lngTemp As Long
Dim lngCount As Long
Dim SlideList() As Variant
Dim Slide As Variant
SlideList = Array(3, 4, 8, 9, 10, 11, 12)
For Each Slide In SlideList
Set sldTemp = ActivePresentation.Slides(Slide)
For lngCount = sldTemp.Shapes.Count To 1 Step -1
With sldTemp.Shapes(lngCount)
If .Type = msoPicture Then
.Delete
End If
End With
Next
Next
End Sub
John Wilson
07-07-2016, 04:02 AM
Does it work? It won't if you have images in Placeholders.
I think I would use change picture command from right click but I can't see your presentation of course.
Since you don't need to work in show mode you could use this to delete from only selected slides
Sub delete_pics()
Dim osld As Slide
Dim opic As Shape
Dim lngCount As Long
On Error GoTo err
err.Clear
For Each osld In ActiveWindow.Selection.SlideRange
For lngCount = osld.Shapes.Count To 1 Step -1
Set opic = osld.Shapes(lngCount)
Select Case opic.Type
Case Is = msoPlaceholder
If opic.PlaceholderFormat.ContainedType = msoPicture Then opic.Delete
Case Is = msoPicture
opic.Delete
End Select
Next lngCount
Next osld
Exit Sub
err:
MsgBox "Did you select slides?"
End Sub
Blueskies
07-07-2016, 04:20 AM
That's very useful. Thanks John.
BVAmateur_12
06-07-2021, 09:09 AM
Hi John,
This is really useful, thanks for sharing.
I'm currently looking to replicate a similar thing but to delete all images in the powerpoint. This is as part of a monthly update of a c. 50 slide powerpoint (believe me I'm looking for ways to improve it!). Would you happen to know how to change the above code so that one click of the macro removes all of the images in the powerpoint instead of slide by slide?
This thread is 5 years old, Please start a new thread, you can link to this one. Thanks.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.