问题
I am getting the following error:
Exception: Service Spreadsheets failed while accessing document with id . . .
when I try to execute a script on a Google sheet. The script worked fine until today.
I believe the problem occurs between these two lines:
var newTab = sheet.duplicateActiveSheet();
sheet.moveActiveSheet(1);
because at the time of the error the duplicate sheet has been created but has not yet been moved to the first position.
Is it possible that the "moveActiveSheet" command suddenly can not
find the new active sheet that has just been created?
If so, is there some other way to do this?
回答1:
There seems to be a bug and it has already been reported.
The issue has been already reported today (15th of December) in the IssueTracker by 13 users (as of now).
Click on the star ⭐ icon to the top/upper-left corner of the webpage to make the issue more popular in order for Google to fix it sooner.
This workaround solution might be useful, I haven't tested it, but you can give it a try.
回答2:
The problem is an internal error in the moveActiveSheet line.
I have found a work around for the problem. In the script comment out the moveActiveSheet line as shown here:
var newTab = sheet.duplicateActiveSheet();
// sheet.moveActiveSheet(1);
sheet.renameActiveSheet(newTabName);
This will result in the new tab being misplaced. You can manually move it to the first position.
Google claims to be working on a fix for this problem. See https://issuetracker.google.com/issues/175625775
回答3:
The bug occurs when pos in sheet.moveActiveSheet(pos) is 1
While the bug is being fixed, as a workaround, instead of e.g. moving the second sheet to the first position, you can move the first sheet to the second position.
Because
sheet.moveActiveSheet(2);
still works.
来源:https://stackoverflow.com/questions/65311243/suddenly-moveactivesheet-returns-an-error-google-apps-script