Home > Enterprise >  How to selet spreadsheet one after another in Google Apps Script?
How to selet spreadsheet one after another in Google Apps Script?

Time:01-29

How to select spreadsheets one after another in Google Apps Script to perform some action in them?

In excel vba the following code worked, but it does not work in Google Apps Script

Dim wb as Workbook
Dim ws as Worksheet

Set wb = ActiveWorkbook
For Each ws in wb.Worksheets

        'Do something here
    End if
Next

Could anyone help me with that?

CodePudding user response:

function myFunction() {
  const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  const sheets = spreadsheet.getSheets();  
  sheets.forEach(sheet => {
    // Do something
  });
}

Note:

  • I strongly recommend taking a look at Apps Script guides. There's a good list of links here, where you can start learning.
  •  Tags:  
  • Related