Consulting

Results 1 to 2 of 2

Thread: Code to delete slides IF they contain pictures of a certain name (e.g. "Picture 2")?

  1. #1
    VBAX Regular
    Joined
    Mar 2019
    Posts
    73
    Location

    Code to delete slides IF they contain pictures of a certain name (e.g. "Picture 2")?

    I have a deck of slides, each containing various objects. I would like to delete any slide that does NOT contain a picture object name EITHER "Picture 2" or "Picture 3".
    It seems like this should be easy, but I'm getting caught up on the For Next/With in the case that the slide is deleted.
    THanks!!!

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Something like this maybe:

    Function hasPicture(oshp As Shape) As Boolean
        If oshp.Type = msoPicture Then
            hasPicture = True
            Exit Function
        End If
        If oshp.Type = msoPlaceholder Then
            If oshp.PlaceholderFormat.ContainedType = msoPicture Then
                hasPicture = True
                Exit Function
            End If
        End If
    End Function
    
    
    
    
    Function hasTargetPic(osld As Slide) As Boolean
        Dim oshp As Shape
        For Each oshp In osld.Shapes
        If hasPicture(oshp) Then
                If oshp.Name = "Picture 2" Or oshp.Name = "Picture 3" Then
                    hasTargetPic = True
                    Exit Function
                End If
                End If
        Next oshp
    End Function
    
    
    Sub deleter()
        Dim S As Long
        For S = ActivePresentation.Slides.Count To 1 Step -1
            If Not hasTargetPic(ActivePresentation.Slides(S)) Then _
            ActivePresentation.Slides(S).Delete
    Next S
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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