I have an issue with Google Apps Script. I have a slide link of Google Slides in a Google Sheets file. I made a copy of both files and I want to update the slide link in the sheet with the new one. Could you help me to find a solution to do it? Because I didn't achieve it.
With the following code you can accomplish your objective; that is to insert into the cell B5
the URL of the third slide. You only need to insert into the code the required IDs and to activate SlidesApp using Resource ⮞ Advanced Google services ⮞ Slides ⮞ On
.
function insertSlideURL() {
var sheet = SpreadsheetApp.openById(
"{SPREADSHEET ID}").getSheetByName("Sheet1");
var cell = "B5";
var presentation = SlidesApp.openById(
"{PRESENTATION ID}");
var slides = presentation.getSlides();
var slide = 3;
var slideURL = presentation.getUrl() + "#slide=id." + slides[slide - 1]
.getObjectId();
sheet.getRange(cell).setValue(slideURL);
}
I hope that this fulfills your requirements. You can change the cell and slide variables to fit another cell/slide configuration.
For more clarification: I used getSlides()
to gather an array of every slide and getObjectId()
to read its ID. Please, write me back if you need further help or more clarification.