Copy sheet to multiple workbooks in a folder

223 views
Skip to first unread message

Michelle Beitzel

unread,
Sep 28, 2020, 1:27:08 AM9/28/20
to Google Apps Script Community
I keep getting this error:

Exception: Unexpected error while getting the method or property openById on object SpreadsheetApp.

When using this script....

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var pasteSheet = [ {name: "2020 RIMP", functionName: "copySheet"}];
  ss.addMenu("Send RIMPS", pasteSheet);
}
function copySheet() {
  var source = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = source.getSheets()[3];
  var sourceFile = DriveApp.getFileById(source.getId());
  var sourceFolder = sourceFile.getParents().next();
  var folderFiles = sourceFolder.getFiles();
  var thisFile; 

  while (folderFiles.hasNext()) {
    thisFile = folderFiles.next();
    if (thisFile.getName() !== sourceFile.getName()){
      var currentSS = SpreadsheetApp.openById(thisFile.getId());
      sheet.copyTo(currentSS);
      currentSS.getSheets()[currentSS.getSheets().length-1].setName('2020 RIMP').activate();
  currentSS.moveActiveSheet(3);
    }    
  };    
}

    
I have one master workbook, and then we have workbooks for each student. When we update the master, we need  to send the new sheets to each student's workbooks. I keep getting an error. I can't figure out what I have done wrong. Please help!

Andrew Roberts

unread,
Sep 28, 2020, 2:31:50 AM9/28/20
to google-apps-sc...@googlegroups.com
You either don't have permission to access that file, or the ID is invalid. I'd put a Logger.log(thisFile.getId()) in there and try manually opening that file.


CONFIDENTIALITY NOTICE: Any email from River View Local School District & attached documents may contain confidential information. All information is intended only for the use of the named recipient. If you are not the named recipient, you are not authorized to read, disclose, copy, distribute or take any action in reliance on the information and any action other than immediate delivery to the named recipient is strictly prohibited. If you have received an email in error, do not read the information and please immediately notify sender by telephone to arrange for a return of the original documents. If you are the named recipient you are not authorized to reveal any of this information to any other unauthorized person.

 https://goo.gl/2061Vs         Please follow us on our Social Media Pages          https://twitter.com/RiverViewLocal

   


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/c5497e43-f811-461f-968e-fb4da077f538o%40googlegroups.com.

Michelle Beitzel

unread,
Sep 28, 2020, 11:34:59 PM9/28/20
to Google Apps Script Community
I think I may have found my issue. I have folders inside of folders. I tried the script on a smaller scale, and it works with files inside the same folder, but it does not work with folders inside of folders. I am looking to see what I can find and see if it is even possible. Lol - I'm just a Kindergarten teacher who needs to take scripting classes! I know enough to be dangerous! Haha!



On Monday, September 28, 2020 at 2:31:50 AM UTC-4, andrew wrote:
You either don't have permission to access that file, or the ID is invalid. I'd put a Logger.log(thisFile.getId()) in there and try manually opening that file.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Darren D'Mello

unread,
Oct 1, 2020, 12:13:37 PM10/1/20
to google-apps-sc...@googlegroups.com
Why no use importrange or query formula in all child sheets. This will ensure always the sheet values are correct?


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

CONFIDENTIALITY NOTICE: Any email from River View Local School District & attached documents may contain confidential information. All information is intended only for the use of the named recipient. If you are not the named recipient, you are not authorized to read, disclose, copy, distribute or take any action in reliance on the information and any action other than immediate delivery to the named recipient is strictly prohibited. If you have received an email in error, do not read the information and please immediately notify sender by telephone to arrange for a return of the original documents. If you are the named recipient you are not authorized to reveal any of this information to any other unauthorized person.

 https://goo.gl/2061Vs         Please follow us on our Social Media Pages          https://twitter.com/RiverViewLocal

   


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/10b937ed-40c8-4d21-8beb-c43d732afbe0o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages