Ronli
Ronli

Reputation: 1

How to add several scripts into one workbook

Google sheets workbook and Apps Script- How can I add more than one Apps Script function to my workbook? I added 'AddColumn' for adding column to 1 sheet and it adds this column to all other sheets, success. I tried to add 'MainSheet' apps script but it removed/replaced the Add Columns function.

Upvotes: 0

Views: 41

Answers (1)

Wicket
Wicket

Reputation: 38391

A Google Apps Script project can include as many functions as you need. You could even create additional files to help you to organize your functions, but keep in mind that the function names should be unique across all the files of the Apps Script project that contains them.

The basic steps are as follows:

  1. Create a new or open an existing spreadsheet
  2. Click Extensions > Apps Script
    • If the spreadsheet doesn't already include an Apps Script project, a new one will be created and included in it.
    • If the spreadsheet includes one or more Apps Script projects, you could add your new function to one of the existing projects. If the spreadsheet contains multiple projects, you will be asked to choose which project should be opened. Once you open a project, besides adding the new function, you can create files (.gs) to organize your functions.

Please remember that Google Apps Script uses JavaScript as a programming language. When writing functions, you should follow the JavaScript syntax rules.

Example

function addColumns(){
   SpreadsheetApp.getActiveSheet().insertColumns(1);

}

function MainSheet(){
   SpreadsheetApp.getSheets()[0].activate();
}

Related

Questions about multiple Apps Script projects bound to a single container

Upvotes: 0

Related Questions