Home > OS >  How do I copy the active file and name it using a value in a Named range - Goolgle script
How do I copy the active file and name it using a value in a Named range - Goolgle script

Time:11-29

I am an expert VBA programmer struggling to come to grips with Google Scripts in Google Sheets. I'm trying to create a copy of the active file and name it from a Named Range. I can get it to copy, but the name of the new file ends up being "Range".

Here is the code I have.

function SaveFileAndCopy() {
  var spreadsheet = SpreadsheetApp.getActive();
  var rffilename = spreadsheet.getRangeByName("rfFileName");
  spreadsheet.copy(rffilename);
  };

CodePudding user response:

In that case, how about the following modification?

From:

var rffilename = spreadsheet.getRangeByName("rfFileName");

To:

var rffilename = spreadsheet.getRangeByName("rfFileName").getValue();
  • In this case, please retrieve the cell value using getValue().
  • Or, you might be able to also use getDisplayValue() instead of getValue(), when you want to use the display value of the cell.

References:

  • Related