Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function copySheets() {
- var copySheetsContaining = Browser.inputBox("Copy sheets with names containing:");
- var destinationId = Browser.inputBox("Enter the destination spreadsheet ID:");
- if (sheetMatch(copySheetsContaining)){
- for (var i = 0; i < sheetsCount; i++){
- var sheet = sheets[i];
- var sheetName = sheet.getName();
- Logger.log(sheetName);
- if (sheetName.indexOf(copySheetsContaining.toString()) !== -1){
- Logger.log("COPY!");
- var destination = SpreadsheetApp.openById(destinationId);
- sheet.copyTo(destination);
- }
- }
- successAlert('copied')
- } else {
- noMatchAlert();
- }
- }
- // determine if any sheets match the user input
- function sheetMatch(sheetMatch){
- for (var i = 0; i < sheetsCount; i++){
- var sheetName = sheets[i].getName();
- if (sheetName.indexOf(sheetMatch.toString()) !== -1){
- return true
- }
- }
- return false
- }
- // alert if no sheets matched the user input
- function noMatchAlert() {
- var ui = SpreadsheetApp.getUi();
- var result = ui.alert(
- 'No Sheets Matched Your Input',
- "Try again and make sure you aren't using quotes.",
- ui.ButtonSet.OK);
- }
- // alert after succesful action (only used in copy)
- function successAlert(action) {
- var ui = SpreadsheetApp.getUi();
- var result = ui.alert(
- 'Success!',
- "You're sheets were " + action + " successfully.",
- ui.ButtonSet.OK);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement