“Every month, manually copying and pasting slide pages for our department reports just to swap out team names and numbers is such a chore…”
“If only there were a way to take a single well-designed template slide and duplicate it automatically for every department using code!”
If you have ever felt this way, you are in luck! In Part 63 of our Google Apps Script (GAS) series—continuing our Google Slides automation journey—we are covering Slide.duplicate() to solve this exact problem!
In the previous session (Part 62), we learned how to search and replace text across an entire presentation using Presentation.replaceAllText().
This time, we are taking things a step further. We will explore an essential, real-world workflow automation technique: duplicating a base template slide programmatically and dynamically generating multiple customized pages!
Keeping with our Sapporo Office theme, we will build a script that takes a single “Sapporo Office Monthly Performance Report” template and batch-generates custom slides for Development, Sales, Customer Support, and Marketing in seconds!
1. What Exactly Is Slide.duplicate()?
Slide.duplicate() is a method that creates an exact copy of a specified slide (page) within a Google Slides presentation.
Just as the name implies, it duplicates the page layout, formatting, elements, and styles with a single line of code.
Understanding the Hierarchy: House, Room, and Furniture
Let’s review our familiar “House, Room, and Furniture” analogy to understand where this method fits into the Google Slides object model:
- [House] = Entire Presentation File (Presentation)
- The file itself, opened via methods like
SlidesApp.openById()introduced in Part 61.
- The file itself, opened via methods like
- [Room] = Individual Slide Page (Slide) ★ Today’s Main Feature!
- Each individual page contained inside the presentation.
- [Furniture] = Page Elements (PageElement / Shape / TextBox, etc.)
- The items placed inside the room (slide), such as text boxes, shapes, tables, and images.
Using Slide.duplicate() is just like taking a fully furnished showroom (template slide) and building an identical replica right next door.
Basic Syntax
// 1. Get the source slide (room) you want to duplicate
var templateSlide = presentation.getSlides()[0];
// 2. Duplicate that slide
var newSlide = templateSlide.duplicate();
By simply chaining templateSlide.duplicate(), a brand-new slide with the exact same design, text, and layout appears immediately after the original slide.
2. STEP 1: Preparation – Create the “Sapporo Office Monthly Performance Report” Slide
Let’s create a sample presentation in Google Drive so we have something to automate with GAS!
Step-by-Step Setup
- Create a new Google Slides presentation in Google Drive
- Open Google Drive and click “+ New” > “Google Slides”.
- Rename the presentation
- Change “Untitled presentation” in the top left to “Sapporo Office Monthly Performance Report”.
- Format the first slide as your template
- Set up the text boxes on the first slide with the following text:
- Title:
{Department} Monthly Performance Report - Subtitle:
Sapporo Office - September 2026 - Body / Notes (Optional):
Monthly Highlights and Key KPI Results for {Department}
- Title:
- * The curly brackets
{Department}act as a placeholder string that our script will target and replace later.
- Set up the text boxes on the first slide with the following text:
- Copy the Presentation ID
- Look at your browser’s address bar (URL) and copy the long string of characters between
https://docs.google.com/presentation/d/and/edit.
- Look at your browser’s address bar (URL) and copy the long string of characters between
That’s all the setup we need!
3. STEP 2: Hands-On – Duplicate a Single Slide with Slide.duplicate()
Now let’s open the Apps Script editor (either standalone or bound to a spreadsheet) and write some code!
We will start simple: fetching the first template slide and duplicating it once using duplicate().
1. Enter the Code
Open the GAS editor, clear any default code, and paste in the following snippet. (Be sure to replace YOUR_PRESENTATION_ID with your actual ID from Step 1.)
function duplicateTemplateSlide() {
// 1. Open the presentation (house) using SlidesApp.openById learned in Part 61
var presentationID = "YOUR_PRESENTATION_ID"; // Enter your Presentation ID here
var presentation = SlidesApp.openById(presentationID);
// 2. Get all slides (rooms) and select the first one
var slides = presentation.getSlides();
var templateSlide = slides[0]; // Index 0 represents the first slide
// 3. Duplicate the template slide!
var newSlide = templateSlide.duplicate();
// 4. Log completion message
Logger.log("Slide duplicated successfully!");
}
2. Line-by-Line Code Breakdown
var presentation = SlidesApp.openById(presentationID);- As covered in Part 61, this command opens the target Google Slides presentation file.
var slides = presentation.getSlides();- Retrieves every slide inside the presentation as an array.
var templateSlide = slides[0];- Because arrays in JavaScript use zero-based indexing,
slides[0]points to the very first slide of the deck.
- Because arrays in JavaScript use zero-based indexing,
var newSlide = templateSlide.duplicate();- The star of today’s lesson! Calling
.duplicate()ontemplateSlideimmediately creates an identical slide placed right after it (at index 1). - Key Takeaway: The
duplicate()method returns the newly createdSlideobject (newSlide). Because of this, you can immediately chain actions to customize that brand-new slide without affecting any other pages!
- The star of today’s lesson! Calling
3. Save and Run
- Click the disk icon (Save) in the top toolbar.
- Make sure the function selector is set to
duplicateTemplateSlide, then click “Run”. - *(If this is your first time running it, Google will ask for permission authorizations. Grant access just as we did in Part 2 and Part 61.)*
4. Verify the Results
Switch back to your Google Slides presentation tab.
You should now see two identical slides reading “{Department} Monthly Performance Report” sitting right next to each other!
4. STEP 3: Practical Application – Auto-Generate Pages for Every Department Using Loops!
Duplicating a single static slide is neat, but having identical duplicate pages doesn’t finish the job.
In everyday workplace automation, what we really want is to duplicate the template, replace the placeholder {Department} on the new slide with “Development”, “Sales”, “Customer Support”, and so on, and repeat until all slides are built!
Let’s combine arrays (introduced in Part 7) with a standard JavaScript forEach loop to create an automated report builder.
1. Enter the Code
function generateDepartmentReports() {
var presentationID = "YOUR_PRESENTATION_ID"; // Enter your Presentation ID
var presentation = SlidesApp.openById(presentationID);
// 1. Get the first slide as our template
var templateSlide = presentation.getSlides()[0];
// 2. Prepare the list (array) of departments to generate slides for
var departmentList = [
"Development Department",
"Sales Department",
"Customer Support Department",
"Marketing Department"
];
// 3. Loop through each department name in the array
departmentList.forEach(function(deptName) {
// Duplicate the template slide to spawn a fresh page
var newSlide = templateSlide.duplicate();
// Replace "{Department}" ONLY within the newly created slide!
newSlide.replaceAllText("{Department}", deptName);
Logger.log("Generated slide for: " + deptName);
});
Logger.log("All departmental slides have been generated successfully!");
}
2. Pro-Tip: The Critical Difference Between Presentation vs. Slide replaceAllText()
Pay close attention to an essential detail here!
In Part 62, we used Presentation.replaceAllText(), which executes a global text replacement across the entire presentation file.
Here, however, we are invoking newSlide.replaceAllText()—scoped exclusively to that single slide!
| Target Object | Method Call | Scope and Impact |
| Presentation (Global) | presentation.replaceAllText("{Department}", "Development Department") | Replaces “{Department}” across every slide in the entire file (overwrites your template slide too!) |
| Slide (Single Page) | newSlide.replaceAllText("{Department}", "Development Department") | Replaces “{Department}” only within that specific slide (leaves all other slides and templates untouched!) |
By calling replaceAllText() directly on newSlide, you update only that freshly duplicated page without touching your original templateSlide or previous pages!
3. Verify the Results
Save your code and run the function.
Now switch back to your presentation. Take a look at the slide list:
- Slide 1:
{Department} Monthly Performance Report(Original template) - Slide 2:
Development Department Monthly Performance Report - Slide 3:
Sales Department Monthly Performance Report - Slide 4:
Customer Support Department Monthly Performance Report - Slide 5:
Marketing Department Monthly Performance Report
In just a few seconds, complete slides for every Sapporo Office department were generated automatically!
Tasks that used to take tedious minutes of copying, pasting, and typing can now be completed effortlessly with Google Apps Script.
5. 4 Common Traps for Beginners and How to Fix Them
When working with Slide.duplicate(), beginners often encounter a few common roadblocks. Let’s review the top four and how to avoid them.
Trap 1: Calling presentation.duplicate() and Triggering a TypeError
// INCORRECT: Calling duplicate on the entire Presentation object
presentation.duplicate();
// Error Message: TypeError: presentation.duplicate is not a function
duplicate() belongs to the Slide object (an individual page), not the Presentation object (the whole file).
Always obtain the slide first—such as via presentation.getSlides()[0]—before calling duplicate().
Trap 2: Replacing Text on the Template Slide Before Duplicating
// INCORRECT ORDER: Replacing text on the template before duplicating it
templateSlide.replaceAllText("{Department}", "Development Department"); // Now the template placeholder is gone!
var newSlide = templateSlide.duplicate();
Always remember the sequence: 1. Duplicate the template (duplicate) ➡ 2. Modify the newly created slide (newSlide). If you modify the template slide first, future loop iterations won’t find the placeholder text anymore!
Trap 3: Losing Track of Slide Positions
When you call duplicate(), the new slide is inserted immediately after the source slide.
If you duplicate slide 1 (slides[0]), the new slide becomes slide 2 (slides[1]).
If you want to move newly generated slides to the very end of your presentation, you can rearrange them using Slide.moveSlide(), which we will explore in a future post.
Trap 4: Leaving the Original Template Slide in the Final Presentation
After running our loop, the very first slide still contains the raw {Department} placeholder.
If you want a clean report deck ready to present, you can delete the template slide right after the loop finishes with one simple line:
// Remove the template slide once generation is complete
templateSlide.remove();
*(We will explore Slide.remove() in detail in Part 71!)*
6. Summary & What’s Next
In this tutorial, we learned how to use Slide.duplicate() to duplicate slide pages programmatically and mass-produce customized slides from a base template.
Quick Recap of Key Takeaways
Slide.duplicate()copies a specific slide page (room) along with all its elements.- It returns the newly created
Slideobject, allowing you to edit the duplicate page immediately. - Use
Slide.replaceAllText()for slide-level text replacement without affecting other pages. - Pairing templates with arrays and loop iterations (
forEach) lets you auto-generate dozens of unique slides in seconds.
Now that you can dynamically scale slides from a template, your Google Slides automation capabilities have grown exponentially!
Next up: once your pages are created, you will probably want to add eye-catching shapes, highlight cards, and dividers to make your KPI reports look sharp and professional.
In Part 64, we will learn how to use Slide.insertShape() to draw custom summary shapes and highlight cards automatically!
Stay tuned, and let’s keep automating presentation design together!
