[GAS Beginner Series #62] Find and Replace Text in Google Slides: Presentation.replaceAllText() and Template Automation

In our previous post (Lesson 61), we kicked off our Google Slides automation journey by learning how to open presentation files programmatically using SlidesApp.openById(), featuring our “Sapporo Office Monthly Performance Report Template”!

Now that you have the key to open presentation files with Google Apps Script (GAS), the next logical step is naturally: “How can I bulk update the text in my template with the latest data?”

Whenever you prepare weekly or monthly report decks, manually clicking through every single slide to retype placeholders like “Target Month,” “Sapporo Office,” or “Achievement Rate” is tedious, time-consuming, and prone to typos or missed updates.

That is why in Lesson 62, we will dive deep into Presentation.replaceAllText()—the most powerful method to find and replace text across an entire Google Slides presentation in an instant!

We will compare it with Google Docs’ Body.replaceText() covered in Lesson 52, explore production-ready sample code based on our Hokkaido/Sapporo office monthly report, and address common beginner pitfalls so you can automate your presentation workflows smoothly and reliably!

1. What is Presentation.replaceAllText()?

Presentation.replaceAllText() is a method that searches an entire Google Slides presentation—across all text boxes, shapes, tables, and even speaker notes—for a specific keyword or placeholder string and replaces every occurrence with new text in one single execution.

Understanding the Slide Hierarchy: The “House, Room, Furniture” Analogy

Let’s reuse our familiar “House, Room, and Furniture” analogy to understand how Google Slides objects are structured in GAS.

Google Slides ConceptReal-World AnalogyMain GAS Object
Entire PresentationEntire Building / HousePresentation
Individual Slide (Page)Each Room / FloorSlide
Text Box, Shape, TableFurniture / Bulletin Boards in the RoomPageElement (TextBox, Shape, Table)

Just like in Google Sheets or Google Docs, the Presentation object represents the entire building.

Normally, updating text inside a specific signboard (TextBox) located in a specific room (Slide) requires a granular multi-step process: identify the room, locate the furniture, and modify the text element.

However, Presentation.replaceAllText() gives an order to the entire building (Presentation), replacing text across every single bulletin board across all rooms at once—making it an exceptionally convenient and powerful tool!

2. Syntax and Parameters for replaceAllText()

Let’s look at the basic syntax and available parameters for replaceAllText().

// Basic syntax (case-insensitive by default)
var count = presentation.replaceAllText(findText, replaceText);

// Case-sensitive syntax
var count = presentation.replaceAllText(findText, replaceText, matchCase);

Parameter Breakdown

  1. findText (1st argument, required): The string to search for (the placeholder or keyword to be replaced).
    • Example: "{Target Month}" or "{Office Name}".
    • Best practice: Always wrap keywords in curly brackets like { } to prevent accidentally replacing unintended words within your slides.
  2. replaceText (2nd argument, required): The new string to insert.
    • Example: "September 2026" or "Sapporo Office".
  3. matchCase (3rd argument, optional): A boolean (true or false) indicating whether the search is case-sensitive.
    • Setting this to true treats "{ABC}" and "{abc}" as distinct strings.
    • If omitted (or set to false), it replaces matching text regardless of casing.

💡 Pro-Tip: Retrieve the Number of Replacements via the Return Value!

When you execute replaceAllText(), it returns an integer indicating the exact number of occurrences replaced across the entire presentation.

var count = presentation.replaceAllText("{Target Month}", "September 2026");
Logger.log("Replaced " + count + " occurrences!");
// Sample log output: Replaced 3 occurrences!

Leveraging this return value allows you to verify whether your script matched the expected number of placeholders, which is invaluable for debugging and error monitoring!

3. STEP 1: Preparation — Create the “Sapporo Office Monthly Performance Report Template”

Let’s set up a sample Google Slides presentation to practice text replacement with Google Apps Script.

Setup Steps

  1. Open Google Drive in your browser, click New > Google Slides to create a blank presentation.
  2. Rename the file in the top-left corner to “Sapporo Office Monthly Performance Report Template”.
  3. Create two slides and populate them with placeholder tags as shown below:

Slide 1 (Cover Page)

  • Title: {Target Month} Sapporo Office Performance Report
  • Subtitle: Location: {Office Name} / Prepared by: {Author Name}

Slide 2 (Main Content)

  • Click the “+” button to add a new slide with the “Title and Body” layout.
  • Title: {Target Month} Key Highlights
  • Body Text Box: ・{Office Name} achieved a 120% sales target achievement rate this month.・Event promotions near Sapporo Dome received great feedback.・Next month's focus: Exclusive Soup Curry collaboration campaign for {Office Name}.
  1. Once created, copy the Presentation ID from the browser URL (the long alphanumeric string between https://docs.google.com/presentation/d/ and /edit).

4. STEP 2: Hands-On — Scripting Batch Replacement for “{Target Month}” and “{Office Name}”

With our template ready, let’s open the Apps Script editor and write the automation code.

In this script, we will replace the three placeholders {Target Month}, {Office Name}, and {Author Name} with updated values in one go!

1. Enter the Code

Open Extensions > Apps Script from an associated Google Sheet (or in a standalone script), and paste the following snippet into the editor:

function updateSapporoReportTemplate() {
  // 1. Specify the target Google Slides ID (replace with your own ID)
  var presentationId = "1a2b3c4d5e6f7g8h9i0j_YOUR_PRESENTATION_ID_HERE";
  
  // 2. Open the presentation (the entire building) using SlidesApp.openById() from Lesson 61
  var presentation = SlidesApp.openById(presentationId);
  
  // 3. Prepare replacement text values
  var targetMonth = "September 2026";
  var officeName = "Sapporo Office";
  var authorName = "Taro Dosanko";
  
  // 4. Batch replace placeholders across the entire presentation using replaceAllText()
  var countMonth  = presentation.replaceAllText("{Target Month}", targetMonth);
  var countOffice = presentation.replaceAllText("{Office Name}", officeName);
  var countAuthor = presentation.replaceAllText("{Author Name}", authorName);
  
  // 5. Output results to the log for verification
  Logger.log("=== Replacement Results ===");
  Logger.log("・{Target Month} : " + countMonth + " replacements made");
  Logger.log("・{Office Name}  : " + countOffice + " replacements made");
  Logger.log("・{Author Name}  : " + countAuthor + " replacements made");
}

2. Step-by-Step Code Walkthrough

  • var presentation = SlidesApp.openById(presentationId);
    • A quick review of Lesson 61! We fetch the entire presentation object and assign it to the presentation variable.
  • var countMonth = presentation.replaceAllText("{Target Month}", targetMonth);
    • This scans every slide for "{Target Month}" and substitutes it with "September 2026". The total number of replacements is saved in countMonth.
  • presentation.replaceAllText("{Office Name}", officeName);
    • Not only does it update the cover page, but it also replaces all three instances of "{Office Name}" on Slide 2 with "Sapporo Office" simultaneously!

3. Save and Run

  1. Click the Save (disk icon) at the top of the editor.
  2. Select updateSapporoReportTemplate as your target function and click Run.
  3. On the first run, grant the requested permissions via the authorization dialog (see Lesson 2).

Check Execution Log

Info    === Replacement Results ===
Info    ・{Target Month} : 2 replacements made
Info    ・{Office Name}  : 4 replacements made
Info    ・{Author Name}  : 1 replacements made

Check Google Slides

Switch back to your Google Slides tab:

  • The cover page title shows “September 2026” instead of “{Target Month}“!
  • “{Office Name}” has turned into “Sapporo Office”!
  • All multiple occurrences of “{Office Name}” in Slide 2 body text have seamlessly updated to “Sapporo Office”!

What used to require tedious searching and manual typing across several pages is completely automated in under a second!

5. Practical Applications: 3 Advanced Patterns for replaceAllText()

Now that you have mastered the basics, here are three practical techniques to supercharge your automation workflows.

Pattern 1: Batch Replacement Using Key-Value Maps and Loops

When you have 10 or 20 placeholder strings, writing out presentation.replaceAllText(...) line after line becomes cumbersome.

By pairing a JavaScript dictionary object with a for...in loop, you can condense the entire operation into a clean, maintainable structure:

function bulkReplaceWithMap() {
  var presentationId = "YOUR_PRESENTATION_ID_HERE";
  var presentation = SlidesApp.openById(presentationId);
  
  // Define replacements as a key-value mapping object
  var replaceMap = {
    "{Target Month}": "October 2026",
    "{Office Name}": "Sapporo Office",
    "{Author Name}": "Hanako Sapporo",
    "{Sales Target}": "$150,000",
    "{Achievement Rate}": "125%"
  };
  
  // Iterate through keys with a for...in loop for automated replacements
  for (var key in replaceMap) {
    var count = presentation.replaceAllText(key, replaceMap[key]);
    Logger.log("Replaced rule " + key + " ➡ " + replaceMap[key] + " (" + count + " matches)");
  }
}

With this pattern, adding new fields in the future only requires adding a single row to replaceMap!

Pattern 2: Populate Slides from Google Sheets Data (Sheets to Slides Automation)

One of the most frequent requests in corporate automation is syncing calculated metrics from Google Sheets straight into presentation decks with a single click.

By using Range.getValue() (covered in Lesson 5) to retrieve spreadsheet cell values and passing them into replaceAllText(), you have a fully automated slide deck reporting engine!

function syncSpreadsheetToSlides() {
  // 1. Fetch values from Google Sheets (Review of Lesson 5)
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var month = sheet.getRange("B2").getValue();     // e.g., "September 2026"
  var sales = sheet.getRange("C2").getValue();     // e.g., 15000000
  var rate  = sheet.getRange("D2").getValue();     // e.g., "120%"
  
  // 2. Open presentation and inject data
  var presentationId = "YOUR_PRESENTATION_ID_HERE";
  var presentation = SlidesApp.openById(presentationId);
  
  presentation.replaceAllText("{Target Month}", month);
  presentation.replaceAllText("{Sales Revenue}", "$" + sales.toLocaleString()); // Format numbers with commas
  presentation.replaceAllText("{Achievement Rate}", rate);
  
  Logger.log("Spreadsheet metrics successfully injected into slides report!");
}

Pattern 3: Strict Case-Sensitive Replacements (Using the 3rd Argument)

If your slide content contains technical acronyms or case-sensitive product codes where "{SEO}" must be differentiated from "{seo}", pass true as the third parameter.

function replaceWithCaseSensitive() {
  var presentation = SlidesApp.openById("YOUR_PRESENTATION_ID_HERE");
  
  // Setting the 3rd argument to true ensures only exact uppercase matches are replaced
  presentation.replaceAllText("{SEO}", "Search Engine Optimization", true);
}

6. 5 Common Traps and Troubleshooting Tips for Beginners

Here are five common pitfalls GAS developers encounter when working with Presentation.replaceAllText(). Reviewing these beforehand will save you hours of head-scratching!

Trap 1: Accidentally Overwriting the Master Template File

This is the #1 mistake made by beginners!

If you call openById() directly on your master template and run replaceAllText(), the placeholder tokens like {Target Month} in your template file will be permanently overwritten with “September 2026”. Once overwritten, the file cannot be reused as a template next month.

💡 Solution: Duplicate the Template in Drive First, Then Replace!

In real-world systems, make it a golden rule to use File.makeCopy() (covered in Lesson 44) to create a fresh copy of your template, and execute text replacements exclusively on the newly generated file.

function generateMonthlyReportSafely() {
  var templateId = "YOUR_TEMPLATE_ID_HERE";
  
  // 1. Duplicate the template file (Review of Lesson 44)
  var templateFile = DriveApp.getFileById(templateId);
  var newFile = templateFile.makeCopy("[Final] September 2026 Sapporo Office Performance Report");
  
  // 2. Open the presentation using the new file's ID
  var presentation = SlidesApp.openById(newFile.getId());
  
  // 3. Perform text replacements on the duplicated file!
  presentation.replaceAllText("{Target Month}", "September 2026");
  
  Logger.log("Created and updated report! URL: " + newFile.getUrl());
}

Following this structure ensures your master template remains untouched and ready for future runs!

Trap 2: Zero Replacements Due to Full-Width vs. Half-Width Bracket Mismatches

If your script looks for standard half-width brackets "{Target Month}", but someone typed full-width Japanese brackets “{Target Month}” on the slide, GAS treats them as completely distinct characters and replaces zero items.

Solution

  • When your log returns 0 replacements, copy the placeholder text directly from the slide canvas into your script to confirm exact character matching.

Trap 3: Mixing Up Method Names with Google Docs’ replaceText()

Learners who recently completed our Google Docs module (Lesson 52) often stumble here:

  • Google Docs: body.replaceText("{Target Month}", "September")
  • Google Slides: presentation.replaceAllText("{Target Month}", "September") (Notice the All!)

Remember that Slides requires replaceAllText, not replaceText!

Trap 4: Text Embedded Inside Flattened Images Cannot Be Replaced

replaceAllText() inspects native slide text containers, tables, and shapes, but it cannot alter text embedded in raster images (JPEG/PNG) or complex grouped vector drawings pasted from third-party tools.

Solution

  • Ensure any target text is placed in standard, editable Google Slides text boxes or native shapes.

Trap 5: Invoking SlidesApp.getActivePresentation() Throws a null Error

When running your script from a Google Sheets editor or a standalone script container, calling SlidesApp.getActivePresentation() will return null because there is no active presentation bound to the execution environment.

Solution

  • When interacting from external scripts, always specify the file explicitly using SlidesApp.openById("SLIDES_ID") as demonstrated in this lesson!

7. Summary & What’s Next

In this guide, we explored how to perform batch text replacements across entire slide decks using Presentation.replaceAllText()!

Key Takeaways

  1. Update text everywhere in your presentation using Presentation.replaceAllText("{Find}", "Replace")!
  2. Track replacement counts via the returned integer for effortless debugging.
  3. Protect master templates by duplicating them with File.makeCopy() prior to modifying content.
  4. Use key-value mapping objects and loops to handle dozens of replacement tokens in concise code.

With this technique in your toolkit, you are completely freed from tedious manual copy-pasting every reporting cycle!

Now that you know how to replace text, your next question might be: “Can I automatically duplicate specific slide layouts depending on how many datasets I have?”

For instance, dynamically duplicating department report pages for Engineering, Sales, and Sapporo Marketing from a single template slide would make your automation even more versatile.

In Lesson 63, we will explore how to duplicate template slides using Slide.duplicate() to generate multi-department presentation decks on the fly!

Stay tuned as we continue expanding your automated presentation skillset!