Status: - I have a spreadsheet with 20 sheets.
- I have another script that copies the sheet from every spreadsheet with every spreadsheet -
- I have to delete some specific sheets every day from a special spreadsheet.
Problem:
When the script sheets are finished to clear, the spreadsheet is hanging and I have to get out and enter the spreadsheet again .
I appreciate that any script:
script: function ShelldileaseSet () {var sheets = ['sheet 1', ' Sheet2 ',' Sheet3 ',' Sheet4 ',' Sheet5 ']; For (var s in sheet) {deleteSheetName (sheet [s]); }} Function deleteSheetName (stname) {var ss = SpreadsheetApp.getActiveSpreadsheet (); Var sh = ss.getSheetByName (stname); If (! Sh) {return; } Ss.setActiveSheet (sh); Ss.deleteActiveSheet (); Utilities.sleep (400); SpreadsheetApp.flush (); }
Try this version I use without problems
function DeleteSheets () {var ss = SpreadsheetApp.getActiveSpreadsheet (); Var sheets = ['Sheet1', 'Sheet2', 'Sheet3']; Var numberoffsits = ss.getSheets (). Length; (Var s = numberOfSheets-1; s & gt; 0-s-) {// In my case, I never change the first sheet spreadsheet app.SetActiveShat (SJSSEE) .s.) [S]); Var shName = SpreadsheetApp.getActiveSheet (). GetName (); If (sheets. Index (shName) gt; -1) {var delSheet = ss.deleteActiveSheet (); Utilities.sleep (500); }} Spreadsheet app.Setactive Sheet (S.Jetsets) [0]); // Send me back to the sheet first You can of course use the argument for the array of functions or - I do this in some cases - this letter I need to keep me in this case, if the condition is different then i sleep can be 400 ms, it is not sure that it does not make any difference, i use 500 because in some time i will find it more reliable Found ... and I ) I do not want to change a working solution; -)
Edit after your comment: To activate the sheet named 'Update' is the last line of this kind of code Change:
SpreadsheetApp.setActiveSheet (ss.getSheetByName ('updated')); Please note that I took this line out of the loop in the original code, sorry for this small error ^^ .
Problem:
When the script sheets are finished to clear, the spreadsheet is hanging and I have to get out and enter the spreadsheet again .
I appreciate that any script:
script: function ShelldileaseSet () {var sheets = ['sheet 1', ' Sheet2 ',' Sheet3 ',' Sheet4 ',' Sheet5 ']; For (var s in sheet) {deleteSheetName (sheet [s]); }} Function deleteSheetName (stname) {var ss = SpreadsheetApp.getActiveSpreadsheet (); Var sh = ss.getSheetByName (stname); If (! Sh) {return; } Ss.setActiveSheet (sh); Ss.deleteActiveSheet (); Utilities.sleep (400); SpreadsheetApp.flush (); }
Try this version I use without problems
function DeleteSheets () {var ss = SpreadsheetApp.getActiveSpreadsheet (); Var sheets = ['Sheet1', 'Sheet2', 'Sheet3']; Var numberoffsits = ss.getSheets (). Length; (Var s = numberOfSheets-1; s & gt; 0-s-) {// In my case, I never change the first sheet spreadsheet app.SetActiveShat (SJSSEE) .s.) [S]); Var shName = SpreadsheetApp.getActiveSheet (). GetName (); If (sheets. Index (shName) gt; -1) {var delSheet = ss.deleteActiveSheet (); Utilities.sleep (500); }} Spreadsheet app.Setactive Sheet (S.Jetsets) [0]); // Send me back to the sheet first You can of course use the argument for the array of functions or - I do this in some cases - this letter I need to keep me in this case, if the condition is different then i sleep can be 400 ms, it is not sure that it does not make any difference, i use 500 because in some time i will find it more reliable Found ... and I ) I do not want to change a working solution; -)
Edit after your comment: To activate the sheet named 'Update' is the last line of this kind of code Change:
SpreadsheetApp.setActiveSheet (ss.getSheetByName ('updated')); Please note that I took this line out of the loop in the original code, sorry for this small error ^^ .
function ShelldileaseSet () {var sheets = ['sheet 1', ' Sheet2 ',' Sheet3 ',' Sheet4 ',' Sheet5 ']; For (var s in sheet) {deleteSheetName (sheet [s]); }} Function deleteSheetName (stname) {var ss = SpreadsheetApp.getActiveSpreadsheet (); Var sh = ss.getSheetByName (stname); If (! Sh) {return; } Ss.setActiveSheet (sh); Ss.deleteActiveSheet (); Utilities.sleep (400); SpreadsheetApp.flush (); }
Try this version I use without problems
function DeleteSheets () {var ss = SpreadsheetApp.getActiveSpreadsheet (); Var sheets = ['Sheet1', 'Sheet2', 'Sheet3']; Var numberoffsits = ss.getSheets (). Length; (Var s = numberOfSheets-1; s & gt; 0-s-) {// In my case, I never change the first sheet spreadsheet app.SetActiveShat (SJSSEE) .s.) [S]); Var shName = SpreadsheetApp.getActiveSheet (). GetName (); If (sheets. Index (shName) gt; -1) {var delSheet = ss.deleteActiveSheet (); Utilities.sleep (500); }} Spreadsheet app.Setactive Sheet (S.Jetsets) [0]); // Send me back to the sheet first You can of course use the argument for the array of functions or - I do this in some cases - this letter I need to keep me in this case, if the condition is different then i sleep can be 400 ms, it is not sure that it does not make any difference, i use 500 because in some time i will find it more reliable Found ... and I ) I do not want to change a working solution; -)
Edit after your comment: To activate the sheet named 'Update' is the last line of this kind of code Change:
SpreadsheetApp.setActiveSheet (ss.getSheetByName ('updated')); Please note that I took this line out of the loop in the original code, sorry for this small error ^^ .
No comments:
Post a Comment