F3LIX BLANC0
F3LIX BLANC0

Reputation: 73

How do I get the current spreadsheet name and NOT sheet name in google scripts?

function onOpen() {
SpreadsheetApp.getActive()
    .getSheets()
    .forEach(function (s, i) {
        if (i === 0) s.getRange('D1').setValue(SpreadsheetApp.getActive().getName());
        s.getRange('D2')
            .setValue(s.getName())
    })
}

The above script only gives me the sheet name NOT the entire spreadsheet name. How do I get it to place the filename in this instance?

In other words, I have a pic below:

Difference between Spreadsheet name and sheet name.

Upvotes: 1

Views: 7754

Answers (2)

Julia
Julia

Reputation: 11

Try this:

function GetWorkbookName() {
return SpreadsheetApp.getActiveSpreadsheet().getName();
}

Upvotes: 1

Ed Nelson
Ed Nelson

Reputation: 10259

To get the name of the Spreadsheet, not Sheets try:

function myFunction() {
  var name = SpreadsheetApp.getActiveSpreadsheet().getName()
Logger.log(name)
}

Upvotes: 5

Related Questions