Results 1 to 6 of 6

Thread: Excel VBA Code to delete slides in PowerPoint

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Excel VBA Code to delete slides in PowerPoint

    Hi,

    I have an excel file with a list of items in a column along with its inclusion as Yes/No in adjacent column. Based on the 'No', I need to delete some slides related to those items from the PowerPoint presentation in the same folder.

    As of now, I have already created a macro to process some tasks in excel. I have also created one to open the relevant PowerPoint from the folder. But while trying to delete (ex. slide 15, 16) using the following, it throws an error 'Run-time error '429': ActiveX component can't create object'

    ActivePresentation.Slides.Range(Array(15, 16)).Delete

    Subsequently, I want to replace slide 15, 16 with the relevant variables.

    Requesting for some help and guidance.

    Thank you,

  2. #2
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,604
    Post Thanks / Like
    Mentioned
    47 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Excel VBA Code to delete slides in PowerPoint

    YOu need to post the rest of the code you have, but you haven't properly qualified Activepresentation with the PP Application object you (presumably) created.

  3. #3
    New Member
    Join Date
    Jun 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel VBA Code to delete slides in PowerPoint

    Hi Rory,

    Thanks for your reply. Here's the PPT part of the Excel code. I am not so good in PowerPoint VBA, hence am trying to work through part by part.

    Code:
    Sub PPT_Part()
    
    
    Dim FileName As String
    Dim PowerPointApp As PowerPoint.Application
    Dim A1, A2 As Integer
        
        Set PowerPointApp = CreateObject("PowerPoint.Application")
        FileName = ActiveWorkbook.Path & "\PPT_Main.pptm"
        PowerPointApp.Presentations.Open (FileName)
        
        ActivePresentation.Slides.Range(Array(15, 16)).Delete
    
    
    End Sub
    Thank you in advance,
    Dubes
    Last edited by RoryA; Jun 20th, 2019 at 08:47 AM.

  4. #4
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,604
    Post Thanks / Like
    Mentioned
    47 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Excel VBA Code to delete slides in PowerPoint

    I'd use another variable for the presentation:

    Code:
    Sub PPT_Part()
    
    
    Dim FileName As String
    Dim PowerPointApp As PowerPoint.Application
    Dim A1, A2 As Integer
        
        Set PowerPointApp = CreateObject("PowerPoint.Application")
        FileName = ActiveWorkbook.Path & "\PPT_Main.pptm"
        dim pres as PowerPoint.Presentation
        set pres = PowerPointApp.Presentations.Open(FileName)
        
        Pres.Slides.Range(Array(15, 16)).Delete
    
    
    End Sub

  5. #5
    New Member
    Join Date
    Jun 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel VBA Code to delete slides in PowerPoint

    Thanks Rory,

    It worked absolutely.

  6. #6
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,604
    Post Thanks / Like
    Mentioned
    47 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Excel VBA Code to delete slides in PowerPoint

    Glad to help.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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