Avatar of Harsh Kumar
Harsh Kumar
Flag for Denmark asked on

VBA - Powerpoint create new presentation and then copy slides from another presentation

Hi guys,

I'm working on creating a tool for powerpoint where I need to create a new PPT and then paste slides ind from a PTT from a specific location.

But i'm having some issues with it, for some reason it simply just paste in the the slides into the first presentation that is open.

please advise.

this is the code I'm using:

Sub pre()

    Dim myPresentation As Presentation

    'Set myPresentation = Presentations.Add(WithWindow:=msoFalse) 'hidden
    Set myPresentation = Presentations.Add(WithWindow:=msoTrue) 'visible

        Call Module1.main

End Sub

Sub main() 

Dim objPresentation As Presentation
Dim i As Integer

'open the target presentation
Set objPresentation = Presentations.Open("c:\temp\Test import2.pptx")
For i = 1 To objPresentation.Slides.Count
    objPresentation.Slides.Item(i).Copy
    Presentations.Item(1).Slides.Paste
Next i
objPresentation.Close

End Sub

Open in new window

VBAMicrosoft PowerPointMicrosoft Office

Avatar of undefined
Last Comment
Harsh Kumar

8/22/2022 - Mon
Rgonzo1971

Hi,

pls try

Sub main()

ActivePresentation.Slides.InsertFromFile "c:\temp\Test import2.pptx", 0

End Sub

Open in new window

Regards
ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Harsh Kumar

ASKER
Whoop whoop! thanks alot! you Rock! it works!
Harsh Kumar

ASKER
I'm been struggling again.. please tell me if i need to make a new question but its simply not working for me if i have more then 1 presentation.. it only add's the last presentation in that is in the code..

please advise here is the code:

Sub create_new_ppt()

    Dim myPresentation As Presentation

    Set myPresentation = Presentations.Add(WithWindow:=msoFalse) 'hidden
    'Set myPresentation = Presentations.Add(WithWindow:=msoTrue) 'visible
    
    
    'Import Presentation
    If crtppt.chk_pres1.Value = True Then
        sTemplate = "c:\test\Test import2.pptx"  '16:9 format
        'Call pres1
    End If

    If crtppt.chk_pres2.Value = True Then
        sTemplate = "c:\test\Test import3.pptx"  '4:3 format
        'Call pres2
    End If
        
        
    Set myPresentation = Presentations.Open(sTemplate, False, True, True)

End Sub

Open in new window



And here is the file i'm working with:

ppt-tool-15082016.ppt
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck