Create a copy of a Google Slides presentation using Apps Script

If you create lots of presentations in Google Slides, it can be useful to create a template that you can quickly copy and edit versus starting from scratch each time.

In this tutorial, I'll show you two ways to create a copy of a Google Slides presentation using Apps Script. AppsScript provides APIs (Application Programming Interfaces) to work with various Google Workspace products such as Drive, Docs, Sheets and Slides. We'll be using the API for Drive and the one for Slides in this tutorial.

Method 1: Using DriveApp to create a copy of the Google Slides presentation

Creating a copy of a Google Slides presentation using DriveApp is straightforward. All we need is the Id of the Google Slides presentation. Once we have this Id, you get the file, make a copy and then rename it. That's it!

function createCopyUsingDriveApp() {
 // The Id of the presentation to copy
 var templateId = "<SLIDES_ID>";

 // Create a copy of the presentation using DriveApp
 var template = DriveApp.getFileById(templateId);
 var fileName = template.getName();
 var copy = template.makeCopy();
 copy.setName("Copy of " + fileName);
}

Method 2: Using SlidesApp to create a copy of the Google Slides presentation

Creating a copy of a Google Slides presentation using SlidesApp is a lot more involved. This is because the SlidesApp API doesn't have a convenient makeCopy() method to create a copy.

Therefore, we need to create a new presentation first, delete the default slides in it and then recreate slides from the original presentation in the new one. This is similar to manually copy pasting each object from one presentation to another. This is tedious when done manually but happens within seconds when automated using Apps Script.

function createCopyUsingSlidesApp() {
 // The Id of the presentation to copy
 var templateId = "<SLIDES_ID>";

 // Access the template presentation
 var template = SlidesApp.openById(templateId);
 var fileName = template.getName();
 var templateSlides = template.getSlides();

 // Create a new presentation first
 // (note: SlidesApp does not support a way to create a copy)
 var newDeck = SlidesApp.create("Copy of " + fileName);

 // Remove default slides
 var defaultSlides = newDeck.getSlides();
 defaultSlides.forEach(function(slide) {
   slide.remove();
 });

 // Insert slides from template
 var index = 0;
 templateSlides.forEach(function(slide) {
   var newSlide = newDeck.insertSlide(index);
   var elements = slide.getPageElements();
   elements.forEach(function(element) {
     newSlide.insertPageElement(element);
   });
   index++;
 });
}

Which method should you use?

Using DriveApp to create the copy is a lot simpler. However, the primary disadvantage is that this method requires the user to give the script access to modify and access all of their files in Google Drive. Even the SlidesApp API requires access to all the presentations in Google Drive but at least the access is scoped to just presentations. Ideally, Google will provide some mechanism to provision access to just a few specific files in Drive. However, if you write the Apps Script, it should be fine to give access because you should know what your script does with your own data.

Conclusion

In this tutorial, I showed you how to create a copy of a Google Slides presentation using Apps Script.

Master Google Sheets Automation

Sign up to receive exclusive Automation tips and tutorials!
I'll send you actionable tips on automating tasks with Google Sheets and coding with Apps Script. You'll also be notified whenever new content is published.
PLUS: Get instant access to my Birthday Reminder Template! 🎂
By signing up you agree to the Privacy Policy & Terms.

Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!