0
votes

I'm testing functionality with this spreadsheet:

https://docs.google.com/spreadsheets/d/1vqPDDOXhzBOkTPbJQDgZTgaGevNEkcglVMUjVUn5FKY/edit?usp=sharing

I've created two custom menus:

Custom views

Module navigation

The Custom views menu shows/hides specific columns based on the menu selection, while the Module navigation menu navigates (or sets the active cell) to a specific cell in the sheet (based on a named range). The problem is that I only want these menus to function in a specific sheet (the "Design" sheet) and not others.

I'm a bit of an Apps Script noob, so I probably haven't set things up optimally, but it works except that it works on any sheet instead of only the Design sheet sheet. I've tried getSheetByName() but that keeps throwing up an error.

The Custom Views I definitely only want working on the Design sheet, but the Module Navigation would be great if it could navigate (or set active cell) to the relevant cell on the Design sheet from any other sheet.

1
If it is desired then you must control the scope of your functions from within the functions themselves. Otherwise any function in a project has potential access to all the sheets in it's container and infact any sheet in other containers that are shared with the current user via openById() or openByUrl().Cooper

1 Answers

3
votes

I created a function in the script which you can use in your code. This is the function:

function isThisSheetCorrect( nameOfSheet ){
  return SpreadsheetApp.getActiveSheet().getSheetName() === nameOfSheet
}

And then in your code, you just run an if statement like this:

if( isThisSheetCorrect("Design") ) {
  // run some code
} else {
 // do nothing or tell the user that they need to use the "Design" sheet
}