Get the spreadsheet name, the current sheet's name and the list of sheets in Google Sheets using Apps Script (2024)

In this tutorial, I'll show you how to get the name of the Google Sheets spreadsheet and the names of the sheets it contains via Apps Script. Since these are custom functions, you can also use them in formulas just like you would use any other function in Google Sheets.

  • How to get the name of the Google Sheets spreadsheet using Apps Script?

  • How to get the name of the currently active sheet using Apps Script?

  • How to get the names of all the sheets in the Google Sheets spreadsheet using Apps Script?

Prerequisites

This tutorial assumes that you're familiar with the basics of Apps Script and Google Sheets. In particular, you should be familiar with:

NoteIf you're new to Apps Script, I've created a series of introductory tutorials that will help you learn coding using Google Sheets and Apps Script.

How to get the name of the Google Sheets spreadsheet using Apps Script?

To get the name of the Google Sheets spreadsheet, we need to first get a reference to the spreadsheet and then use the getName() method of the Spreadsheet object to get its name.

/** * Returns the name of the Google Sheets spreadsheet. * * @return The name of the Google Sheets spreadsheet. * @customfunction */function SPREADSHEETNAME() { let ss = SpreadsheetApp.getActive(); return ss.getName();}

How to get the name of the currently active sheet using Apps Script?

To get the name of the currently active sheet, we need to first get a reference to the spreadsheet. Then we use the getActiveSheet() method of the Spreadsheet object to get the sheet that is active. Finally, we use the getName() method of the Sheet object to get its name.

/** * Returns the name of the active sheet. * * @return The name of the active sheet. * @customfunction */function SHEETNAME() { let activeSheet = SpreadsheetApp.getActiveSheet(); return activeSheet.getName();}

How to get the names of all the sheets in the Google Sheets spreadsheet using Apps Script?

To get the names of all the sheets in a Google Sheets spreadsheet, we need to first get a reference to the spreadsheet. Then we need to get all the sheets in it using the getSheets() method of the Spreadsheet object.. Finally, we get the name of each sheet using the getName() method of the Sheet object.

/** * Returns the names of all sheets. * * @return The name of all sheets in the Google Sheets spreadsheet. * @customfunction */function ALLSHEETNAMES() { let ss = SpreadsheetApp.getActive(); let sheets = ss.getSheets(); let sheetNames = []; sheets.forEach(function (sheet) { sheetNames.push(sheet.getName()); }); return sheetNames;}

Conclusion

In this tutorial you learned how to programmatically get the name of the Google Sheets spreadsheet and the names of the sheets in it using Apps Script.

Hope you found this tutorial helpful. Thanks for reading!

Stay up to date

Follow me via email to receive actionable tips and other exclusive content. I'll also send you notifications when I publish new content.

By signing up you agree to the Privacy Policy & Terms.

Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!

Get the spreadsheet name, the current sheet's name and the list of sheets in Google Sheets using Apps Script (2024)
Top Articles
Services
Microsoft 365 advanced protection - Microsoft Support
Fighter Torso Ornament Kit
Public Opinion Obituaries Chambersburg Pa
Directions To Franklin Mills Mall
Pnct Terminal Camera
Jailbase Orlando
Apex Rank Leaderboard
Meer klaarheid bij toewijzing rechter
Brgeneral Patient Portal
A Complete Guide To Major Scales
Volstate Portal
Max 80 Orl
Craigslist Labor Gigs Albuquerque
Culvers Tartar Sauce
Athens Bucket List: 20 Best Things to Do in Athens, Greece
Sound Of Freedom Showtimes Near Cinelux Almaden Cafe & Lounge
How do I get into solitude sewers Restoring Order? - Gamers Wiki
Gayla Glenn Harris County Texas Update
Amih Stocktwits
Homeaccess.stopandshop
R. Kelly Net Worth 2024: The King Of R&B's Rise And Fall
Disputes over ESPN, Disney and DirecTV go to the heart of TV's existential problems
Skycurve Replacement Mat
Suspiciouswetspot
Lacey Costco Gas Price
Marokko houdt honderden mensen tegen die illegaal grens met Spaanse stad Ceuta wilden oversteken
How do you get noble pursuit?
Earthy Fuel Crossword
Rubmaps H
Ilabs Ucsf
Robot or human?
Hair Love Salon Bradley Beach
Tal 3L Zeus Replacement Lid
Chs.mywork
Keeper Of The Lost Cities Series - Shannon Messenger
Stanford Medicine scientists pinpoint COVID-19 virus’s entry and exit ports inside our noses
Myanswers Com Abc Resources
Craigs List Hartford
Weather Underground Cedar Rapids
Nami Op.gg
Chase Bank Zip Code
Watch Chainsaw Man English Sub/Dub online Free on HiAnime.to
Unblocked Games - Gun Mayhem
FactoryEye | Enabling data-driven smart manufacturing
Campaign Blacksmith Bench
Sams La Habra Gas Price
Escape From Tarkov Supply Plans Therapist Quest Guide
Unity Webgl Extreme Race
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6432

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.