Google-sheets – retrieve the names of sheets in a public document

google sheetsimportrange

I am currently using the function IMPORTRANGE in a Google spreadsheet to pull information from a public document using the URL.

I have to supply a range_string in the format "Sheet Name!A1:D21" to select cells A1:D21 of sheet "Sheet Name" in the shared document.

Is there any way for me to get the list of sheets that are currently in the other document? Sheets are added by others, and currently I have to manually enter that information into the document where IMPORTRANGE is being used.

Alternatively, is it possible to have a range_string that uses an index of some sort, such as "[0]!A1:D21" to get cells A1:D21 in the first sheet of the other document?

Best Answer

Google Sheets doesn't have built-in functions that return a list of the sheet names and it's not possible to use something like [0]!A1:D21 in formulas to refer to a range in the first sheet of the spreadsheet.

The alternative to automatically get a list of the sheet names is to use Google Apps Script. You could create a custom function to get the list of the sheet names or even you could use Apps Script to import the values of the external spreadsheet.

References