Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-11
4
Medium Priority
?
783 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 53

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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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 …

824 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