Copy Slides From One Presentation to Another (VBA for PowerPoint)

In this article I will explain how you can copy slides from one PowerPoint presentation to another using VBA.

Example 1

Sub main()
Dim objPresentation As Presentation
Dim i As Integer

'open the target presentation
Set objPresentation = Presentations.Open("C:\2.pptx")
For i = 1 To objPresentation.Slides.Count
    objPresentation.Slides.Item(i).Copy
    Presentations.Item(1).Slides.Paste
Next i
objPresentation.Close
End Sub

This is the presentation with the macro before running the script:
Before Running the Code
This the presentation with the slide we want to copy:
Slides to Copy
Result:
Result

Preserve Formatting When Copying Slides

The problem with the previous example was that original presentations theme formatting was not copied over. Assume the 2 sheets had different formatting, this is what would have happened:
Before Running the Code
This the presentation with the slide we want to copy:
Slides to be copied
Result:
Result
In order to overcome this issue you could use the code below:

Sub Example2()
Dim objPresentation As Presentation
Dim i As Integer

'open the target presentation
Set objPresentation = Presentations.Open("C:\2.pptx")
For i = 1 To objPresentation.Slides.Count
    objPresentation.Slides.Item(i).Copy
    Presentations.Item(1).Slides.Paste
    Presentations.Item(1).Slides.Item(Presentations.Item(1).Slides.Count).Design = _
        objPresentation.Slides.Item(i).Design
Next i
objPresentation.Close
End Sub

Asides from copying the slide the code above copies the design. If you wanted to do this manually you would copy the slidemaster over to the new presentation. You can’t copy the slidemaster using VBA but instead you can set the design property of the slides.

Download Sample Files.

Leave a Reply

Your email address will not be published. Required fields are marked *