Results 1 to 7 of 7

Thread: Deleting pictures using code

  1. #1

    Deleting pictures using code

    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

  2. #2
    VBAX Master
    Feb 2007
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials

  3. #3
    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
    End If
    End With

    End Sub

  4. #4
    VBAX Master
    Feb 2007
    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
       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
             End Select
          Next lngCount
       Next osld
       Exit Sub
       MsgBox "Did you select slides?"
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials

  5. #5
    That's very useful. Thanks John.

  6. #6
    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?

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Oct 2006
    Near Columbia
    This thread is 5 years old, Please start a new thread, you can link to this one. Thanks.
    I expect the student to do their homework and find all the errrors I leeve in.

    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts