Solved

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

Posted on 2016-08-11
4
339 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 51

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 51

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

Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

Question has a verified solution.

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

Outlook Free & Paid Tools
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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…

734 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