[VBA] Opening an existing Presentation File from Excel and adding new slide in a for loop

sanfrandear

New Member
Joined
Aug 20, 2019
Messages
4
I have a macro here that works fine when creating a new presentation, but now I have a specific layout that I need to use from an existing presentation . So I was thinking I could open the presentation and add a new slide for every loop. I tried the getobject method but kept running into an error.

Code:
Sub FilterPackage()



Dim newppt As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide




On Error Resume Next
    Set newppt = GetObject(, "PowerPoint.Application")
On Error GoTo 0


If newppt Is Nothing Then
    Set newppt = New PowerPoint.Application
End If


If newppt.Presentations.Count = 0 Then
    newppt.Presentations.Add
End If


'For Loop to filter and then export charts as picture to new slide
For i = 1 To lastcolumn
l


        
'Create new slide
newppt.ActivePresentation.Slides.Add newppt.ActivePresentation.Slides.Count + 1, ppLayoutTitleOnly
newppt.ActiveWindow.View.GotoSlide newppt.ActivePresentation.Slides.Count
Set activeSlide = newppt.ActivePresentation.Slides(newppt.ActivePresentation.Slides.Count)
activeSlide.Select
activeSlide.Shapes.Title.TextFrame.TextRange.Text = rangetitle


'code pastes graphs onto new slide 
Next i


End Sub


I tried the following methods but ran into an error:

1.
Code:
Set MyPresentation = objNewPowerPoint.Presentations.Open(filepath)


2.
Code:
Dim oPPT As PowerPoint.Application
Dim oPres As Object
Dim oSlide As Object


    Set oPPT = GetObject(, "PowerPoint.Application")
    
    Set oPres = oPPT.Presentations(filepath)


    Set oSlide = oPres.Slides.Add(oPres.Slides.Count + 1, 12) 'ppLayoutBlank
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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