1
votes

I am trying to rename my Google Sheets File name based on contents of at least one cell (ideally, it would be a combination of information from two cells: B2 and D2, but I can make contents of one cell work).

I am able to change the worksheet name from the contents of one cell, but am struggling to change the actual file name.

1
Could you add some code to show us what you have tried and exact parts you are struggling with? - D Malan

1 Answers

2
votes

To change the Spreadsheet's name you will need DriveApp too and change its filename. Try this example:

// get the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();

// get a value from the B2 cell on sheet "Sheet" as new filename
var newFileName = ss.getRange("Sheet!B2").getValue();

// get the spreadsheet ID
var ssID = ss.getId();

// get the spreadsheet file by ID
var ssFile = DriveApp.getFileById(ssID);

 // set new filename for the spreadsheet
ssFile.setName(newFileName);