11

I'm having an issue. Whenever I create a new spreadsheet, I'm not able to add a script I've already created. The list for recent projects or scripts is always blank. Anyone have a resolution or do I always have to copy the script code and insert it into the spreadsheet?

1 Answer 1

10

You can add your script as a library in the new spreadsheet. Lets start from the beginning. This sample code will add a string to the active cell:

function libTest(text) {
  var sh = SpreadsheetApp.getActiveSpreadsheet()
    .getActiveSheet().getActiveCell();
  sh.setValue(text);
}

Save the script, by creating a version:
enter image description here

Next, copy the Project Key from the script editor:
enter image description here
enter image description here

Publish the script as a web app (execute only you):
enter image description here

In the new spreadsheet, open the script editor. Chose Manage Libraries from the resources option and enter and select the key/library:
enter image description here

In the script editor you can now add the following code:

function test(){
  libTest.libTest("jacobjan");
}
1
  • 1
    Thanks. This was very clear and helpful.
    – gwintrob
    Jan 22, 2021 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.