appscript.dev
Automation Intermediate Slides Sheets

Auto-refresh charts in Slides from a Sheet

Update embedded Sheet charts in a Northwind deck on a schedule — never present stale data.

Published Jul 6, 2025

Northwind keeps a standing deck for client updates with charts pulled from a performance Sheet. Google Slides does not refresh those embedded charts on its own — when the Sheet data moves, each chart in the deck still shows whatever it showed when it was last linked. Someone has to open the deck, click every chart, and choose Update. Skip that and the meeting runs on last month’s numbers.

This script does the clicking. It opens the deck, finds every linked Sheets chart on every slide, and refreshes each one against its source. Run it on a schedule and the deck is always current the moment you open it.

What you’ll need

  • A Google Slides deck with one or more charts inserted from a Sheet using Insert → Chart → From Sheets with the Link to spreadsheet option ticked.
  • The deck’s file ID, and edit access to the deck for the account running the script.
  • The source Sheet shared with that same account, so the refresh can read the current data.

The script

// The deck whose linked charts should be refreshed.
const DECK_ID = '1abcDeckId';

/**
 * Opens the deck and refreshes every linked Sheets chart on every
 * slide, so each chart matches its source spreadsheet.
 */
function refreshLinkedCharts() {
  const deck = SlidesApp.openById(DECK_ID);
  const slides = deck.getSlides();

  // Guard: an empty deck has nothing to refresh.
  if (!slides.length) {
    Logger.log('Deck has no slides — nothing to refresh.');
    return;
  }

  let refreshed = 0;

  // Walk every slide in the deck.
  for (const slide of slides) {
    // Each slide may hold several linked Sheets charts.
    for (const sheetsChart of slide.getSheetsCharts()) {
      // Pull the latest data from the source spreadsheet.
      sheetsChart.refresh();
      refreshed++;
    }
  }

  Logger.log(`Refreshed ${refreshed} linked chart(s).`);
}

How it works

  1. refreshLinkedCharts opens the deck by ID and reads every slide with getSlides().
  2. If the deck has no slides it logs a message and stops — no wasted work.
  3. It loops the slides one by one.
  4. For each slide it calls getSheetsCharts(), which returns only the charts that were inserted from a Sheet and linked — ordinary images and native shapes are ignored.
  5. It calls refresh() on each linked chart, which re-fetches the data from the source spreadsheet and redraws the chart in the deck.
  6. It counts the charts it touched and logs the total, so a scheduled run leaves a trace you can check.

Example run

The source Sheet has a quarterly revenue table that gets updated each morning. The deck has three slides, each with one linked chart.

Before the run, the charts show Monday’s figures. After refreshLinkedCharts, the execution log reads:

Refreshed 3 linked chart(s).

Open the deck and every chart now matches Tuesday’s data — no clicking Update on each one.

Trigger it

Run this on a daily schedule so the deck is fresh before anyone opens it:

  1. In the Apps Script editor open Triggers (the clock icon).
  2. Add a trigger for refreshLinkedCharts, Time-driven, Day timer, set to run between 6am and 7am.
  3. Approve the authorisation prompt. The deck’s charts now refresh every morning ahead of the working day.

Watch out for

  • Only charts inserted from a Sheet with linking enabled are refreshed. A chart pasted as a static image, or one not linked, is invisible to getSheetsCharts().
  • The refresh redraws each chart but keeps its existing size and position. If the underlying chart type or axes change in the Sheet, re-insert the chart rather than relying on a refresh.
  • The script needs access to both the deck and the source Sheet. If the Sheet is later restricted, the refresh fails silently for that chart.
  • A deck with many charts can be slow to refresh, since each chart is a separate fetch. Keep an eye on the six-minute execution limit for very large decks.
  • A run only updates the saved deck. Anyone with the deck already open must reload it to see the new charts.

Related