Reputation: 73
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
Reputation: 11
Try this:
function GetWorkbookName() {
return SpreadsheetApp.getActiveSpreadsheet().getName();
}
Upvotes: 1
Reputation: 10259
To get the name of the Spreadsheet, not Sheets try:
function myFunction() {
var name = SpreadsheetApp.getActiveSpreadsheet().getName()
Logger.log(name)
}
Upvotes: 5