Excel VBA Code to delete slides in PowerPoint

Dubes

New Member
Joined
Jun 20, 2019
Messages
3
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,
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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.
 
Upvote 0
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 a moderator:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top