TypeError: SpreadsheetApp.getActiveSpreadsheet(...).getSheetbyName is not a function

2,865 views
Skip to first unread message

Emily Peterson

unread,
Aug 25, 2022, 2:30:27 AM8/25/22
to Google Apps Script Community
I am trying to use the script below, but am getting the error below. Can anyone. help me understand what I am doing incorrectly? Much appreciated!


Script:

function createNewGoogleDocs(){

  const googleDocTemplate = DriveApp.getFileById('1dCzNrne3JrnOusk6haDJsnNqbv558fY6YBRCnvE5tDE');
  const destinationFolder = DriveApp.getFolderById('16BWlpECwn6qfZgqj3UficlaGfMTKdaat');
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetbyName('Data');
  const rows = sheet.getDataRange().getValues();

Error:
TypeError: SpreadsheetApp.getActiveSpreadsheet(...).getSheetbyName is not a function

Laurie J. Nason

unread,
Aug 25, 2022, 2:35:16 AM8/25/22
to google-apps-sc...@googlegroups.com
You’ve got a typo in the name the By should be capitalized

getSheetbyName
getSheetByName





------ Original Message ------
From "Emily Peterson" <emily.elizab...@gmail.com>
To "Google Apps Script Community" <google-apps-sc...@googlegroups.com>
Date 25/08/2022 09:30:27
Subject [Apps-Script] TypeError: SpreadsheetApp.getActiveSpreadsheet(...).getSheetbyName is not a function

--
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/c2331cb3-b2d9-43c0-8b41-0caf4c4ce9b1n%40googlegroups.com.

Ed Sambuco

unread,
Aug 26, 2022, 4:20:02 PM8/26/22
to google-apps-sc...@googlegroups.com
Your sheet variable is likely null.  Do you actually have an active spread sheet?  If you're running this script standalone, probably not.

Emily Peterson

unread,
Aug 26, 2022, 7:23:39 PM8/26/22
to google-apps-sc...@googlegroups.com
Fixed! Was as simple as capitalizing the B in By. Thanks for the help. I stared at this for way too long. 

On Aug 26, 2022, at 4:20 PM, Ed Sambuco <esamb...@gmail.com> wrote:


You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/a5vIoBFfjLs/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAANZsGMfLcbuU0TdHbZR_h%3DE2FN8wGhE17JoLnVO2OWm1SbsjA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages