How to reference a Google Sheet by filename?

I would like to use IMPORTRANGE function, but it can only reference a file by URL not by filename.

Example filename:

  • 2018-11.xlsx
  • 2018-12.xlsx

1 Answer 1


Google Sheets hasn't a built-in function to make reference a Google Sheet by filename and a custom function can't be used because they ran anonymously and the Google Apps Script Google Drive and Google Drive Advanced services require authorization to use them.

The only way is by using scripts triggered by other means like a macro, a custom menu, dialog or installable triggers or script editor.

You could DriveApp.searchFiles(params) to get a collection of files with the specified name, then use file iterator to loop through that collection.

Example from the above link

// Log the name of every file in the user's Drive that modified after February 28,
// 2013 whose name contains "untitled".
var files = DriveApp.searchFiles(
    'modifiedDate > "2013-02-28" and title contains "untitled"');
while (files.hasNext()) {
  var file = files.next();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.