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.
Asked
Active
Viewed 1,758 times
2 Answers
1
You need to construct the slide URL manually, using the Object ID from Slide.getObjectID()
Here is an example which will log the URL's for each slide in a presentation.
function getSlideURLS() {
var presentation = SlidesApp.getActivePresentation();
var base_url = presentation.getUrl();
var slides = presentation.getSlides();
for(var i in slides){
var slide_url = base_url+'#slide=id.'+slides[i].getObjectId();
Logger.log(slide_url);
}
}

Cameron Roberts
- 7,127
- 1
- 20
- 32
-
Ok I believe it is ok but I would like to choose a specific slide for example in the cell "B5" in the google sheet I want to update the link of the slide number 3 when I make a copy of both files. With your code above it takes the link of the last slide.. I tried but it was a failure, do you have any ideas ? Thanks in advance. – Ant Las Jan 23 '20 at 15:16
-
It is ok I achieved my objectif. Now I try to change the hyperlink by a name – Ant Las Jan 23 '20 at 15:56
-
This code was just an example of building the URL for all slides, I've updated the answer to mention that. – Cameron Roberts Jan 23 '20 at 16:31
-
Thanks I accomplish my objective ! – Ant Las Jan 24 '20 at 09:39
-
Is it possible to use the name rather than the slide number ? – Ant Las Jan 27 '20 at 10:49
-
I used this link in a Table of Contents inside a presentation and it opens a new copy of the presentation on the linked slide. To stay inside the existing instance omit the presentation URL. Just use '#slide=id.'+slides[i].getObjectId(); – aNewb Mar 20 '21 at 22:32
0
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.

Jacques-Guzel Heron
- 2,480
- 1
- 7
- 16
-
Hi there @AntLas! If this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/a/5235/589350) by clicking the checkmark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Jacques-Guzel Heron Jan 24 '20 at 14:19