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??
To anyone struggling with the same issue, here is the subroutine that I managed to create. The
objDestPresentationshould be a Presentation Object and thesourceSlideRangeshould be a SlideRange Object.This will copy the slides from
sourceSlideRangeto the end of theobjDestPresentation. Hopefully this will save someone some of the struggle that I went through!