Solved

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

Posted on 2016-08-11
4
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41752067
Hi,

pls try

Sub main()

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

End Sub

Open in new window

Regards
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41752100
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
ID: 41752118
Whoop whoop! thanks alot! you Rock! it works!
0
 
LVL 1

Author Comment

by:Hakum
ID: 41756612
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

626 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