Consulting

Results 1 to 5 of 5

Thread: Select most items on a slide and delete them

  1. #1

    Select most items on a slide and delete them

    I want to

    1. select a particular slide from the active presentation
    A. assuming something like the following for slide number 8
    ActivePresentation.Slides(8).Select
    2. select/Delete most of the shapes that are on that slide.
    A. if the shape has the word "placeholder" it will stay on the slide
    B. a slide could have 2 items or 5.
    C. names of pictures will vary
    D. they could have Rectangle 5, Slide Number Placeholder1, and Picture 3 as names
    3. then I will insert a photo from a file to replace the deleted one(s)....

    my focus for this question is selecting the items and getting them deleted.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    https://docs.microsoft.com/en-us/off...e.msoshapetype

    https://docs.microsoft.com/en-us/off...laceholdertype

    i wouldn't trust the .Name

    I think it'd be safer to use Shape.Type and Shape.PlaceHolderFormat.Type

    Option Explicit
    
    
    Sub test()
        Dim oPres As Presentation
        Dim oSlide As Slide
        Dim oShape As Shape
        
        Set oPres = ActivePresentation
        
        For Each oSlide In oPres.Slides
            For Each oShape In oSlide.Shapes
                With oShape
                    If .Type = msoPlaceholder Then
                        If .PlaceholderFormat.Type = ppPlaceholderCenterTitle Then
                            MsgBox "Title"
                        End If
                    
                    ElseIf .Type = msoPicture Then
                        MsgBox "Picture"
                
                    Else
                        MsgBox "Somethin Else"
                    End If
                End With
            Next
        Next
    
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Maybe this would work

    Sub killer()
    Dim osld As Slide, L As Long
    Set osld = ActivePresentation.Slides(1)' change number
    For L = osld.Shapes.Count To 1 Step -1
    If osld.Shapes(L).Type <> msoPlaceholder Then
    osld.Shapes(L).Delete
    End If
    Next
    End Sub
    In PPT always try to avoid select shapes / slides in code unless it is really necessary BTW. Work on a copy just in case.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    John's code worked perfectly. I am going to use Paul's code to add additional code to insert the new photo after the slides are successfully deleted.
    thank you for the easy to understand explanations. you guys are amazing

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Be advised that if you have Grouped Shapes, then they might require some special checks
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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