I'm trying to write a subroutine that will copy and paste all (and later only some) of the slides from a powerpoint file to another keeping source formatting.
This is the closest I have gotten:
Dim objPowerpointApp, objPresentations
Set objPowerpointApp = CreateObject("Powerpoint.Application")
Set objPresentations = objPowerpointApp.Presentations
Dim objNewPresentation
Set objNewPresentation = objPresentations.Open(strTemplateFile, 0, 0, -1)
Dim objOldPresentation : Set objOldPresentation = objPresentations.Open(tempSlideSet.Path, 0, 0, 0)
Dim tempCurrentSlide
For Each tempCurrentSlide in objOldPresentation.Slides
tempCurrentSlide.Copy
objNewPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")
Next
It throws no errors and even pastes the correct slide masters, but it doesn't actually paste any of the slides.
I've also tried this:
Dim objPowerpointApp, objPresentations
Set objPowerpointApp = CreateObject("Powerpoint.Application")
Set objPresentations = objPowerpointApp.Presentations
Dim objNewPresentation
Set objNewPresentation = objPresentations.Open(strTemplateFile, 0, 0, -1)
Dim objOldPresentation : Set objOldPresentation = objPresentations.Open(tempSlideSet.Path, 0, 0, 0)
Dim tempCurrentSlide
For Each tempCurrentSlide in objOldPresentation.Slides
tempCurrentSlide.Copy
objNewPresentation.Slides.Paste
objNewPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")
Next
Which pastes the correct slide master as well as the slide, but the slide is pasted with the destination formatting.
Naturally, this pastes all the slides correctly, but without any of the source formatting:
Dim objPowerpointApp, objPresentations
Set objPowerpointApp = CreateObject("Powerpoint.Application")
Set objPresentations = objPowerpointApp.Presentations
Dim objNewPresentation
Set objNewPresentation = objPresentations.Open(strTemplateFile, 0, 0, -1)
Dim objOldPresentation : Set objOldPresentation = objPresentations.Open(tempSlideSet.Path, 0, 0, 0)
Dim tempCurrentSlide, lngSlideIndex
For Each tempCurrentSlide in objOldPresentation.Slides
lngSlideIndex = objNewPresentation.Slides.Count
objNewPresentation.Slides.InsertFromFile tempSlideSet.Path, lngSlideIndex
Next
From what I can find in documentation and others' experience, the first option should work as I need, so I really am stuck at this point.
How can I copy and paste a powerpoint slide using VBScript and keep its source formatting??
You first need to Activate the Window of the target slidedeck before pasting with the "PasteSourceFormatting" option
when TargetPPT is the destination presentation in VBA, and if I want to copy all slides of SourcePPT:
The slides are pasted at the current active slide Use
Application.ActiveWindow.View.GotoSlide (5)
to position f.i. on slide 5 first, and paste the new slides after slide 5.