Open Google Docs Spreadsheet by name

user1807201 picture user1807201 · Jan 8, 2013 · Viewed 21.7k times · Source

I have a situation where a script is taking input data and sending it to a spreadsheet. After a while, this spreadsheet becomes too big.

Right now we have to manually move the items from the the primary spreadsheet to a new one. The reason is that not everyone is familiar with the code and are willing to change the ID in the code.

I would like to know if there is a way to open the spreadsheet by name. If not, is there a better way of achieving what we need (described above)

Answer

Dan picture Dan · May 1, 2015

The DocsList service used in one of the answers no longer functions as it has been depreciated. I updated my scripts to look more like the following.

// Open the file
  var FileIterator = DriveApp.getFilesByName(FileNameString);
  while (FileIterator.hasNext())
  {
    var file = FileIterator.next();
    if (file.getName() == FileNameString)
    {
      var Sheet = SpreadsheetApp.open(file);
      var fileID = file.getId();
    }    
  }

The replacement for DocsList is DriveApp https://developers.google.com/apps-script/reference/drive/drive-app