0

I have a google doc ID (just the ID as a value) in a cell on a spreadsheet. I want to point a Var to grab that value form the spreadsheet (doc ID) and then use it in the SlidesApp.openbyId.

For example:

var slideId = Sheets.Spreadsheets.Values.get('1aXXXXXXXXXXw', 'Run!E4:E4');
var slide = SlidesApp.openById(slideId);

When the script runs and gets to the var slide = SlidesApp.openById(slideId); I get: Not found (line 101, file "Code")

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
Ahaze
  • 1
  • 1
  • 2
    Although I cannot understand the requirement for using Sheets API in your case, if you can use Spreadsheet service, how about modifying `var slideId = Sheets.Spreadsheets.Values.get('1aXXXXXXXXXXw', 'Run!E4:E4');` to `var slideId = SpreadsheetApp.openById('1aXXXXXXXXXXw').getRange('Run!E4:E4').getValue();`? If you are required to use Sheets API, how about modifying `var slideId = Sheets.Spreadsheets.Values.get('1aXXXXXXXXXXw', 'Run!E4:E4');` to `var slideId = Sheets.Spreadsheets.Values.get('1aXXXXXXXXXXw', 'Run!E4:E4').values[0][0];`? – Tanaike Sep 18 '19 at 01:37
  • Work perfect! Thank you! – Ahaze Sep 19 '19 at 23:06

1 Answers1

0

I'd recommend you first get the range > value, assign it to a variable & then use that variable in SlidesApp.openbyId.

Here's what I'd do -

var slideId = SpreadsheetApp.getActiveSpreadsheet().getRange("A1").getValue();
var slide = SlidesApp.openById(slideId);

Please replace the A1 to wherever the doc ID has been stored.

In case you have a list of doc IDs (unclear per OP), then the solution would slightly vary to getDataRange and getValues (plural), which would then be routed through a "for" loop so we could iterate through every single doc ID.

Sourabh Choraria
  • 2,255
  • 25
  • 64