Solved

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

Posted on 2016-08-11
4
98 Views
Last Modified: 2016-08-15
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

0
Comment
Question by:Hakum
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

pls try

Sub main()

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

End Sub

Open in new window

Regards
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Or simply
 sTemplate = "c:\temp\Test import2.pptx"

    Set myPresentation = Presentations.Open(sTemplate, False, True, True)

Open in new window

0
 
LVL 1

Author Closing Comment

by:Hakum
Comment Utility
Whoop whoop! thanks alot! you Rock! it works!
0
 
LVL 1

Author Comment

by:Hakum
Comment Utility
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
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now