Skip to content Skip to sidebar Skip to footer

Hiding Worksheets From Specific Users Inside A Spreadsheet

Sorry I'm not familiar with coding, I have a spreadsheet with multiple worksheets, it's shared with many people, I'm trying to make those sheets hidden by defaults when it's share

Solution 1:

Your project has two main problems

  1. Authorization
  2. Algorithm

Authorization

You are missing the restrictions of onOpen and Class Session.

onOpen is a reserved name for the open simple trigger. When it's triggered by an open event, then can't execute methods that require authorization.

Session.getEffectiveUser().getEmail() and Session.getActiveUser().getEmail() might work when the owner open the spreadsheet but will return an empty string when the spreadsheet is opened by an editor. Related question: Session.getActiveUser().getEmail() returns no Value

One trick to use a custom menu to save the active user email address on the User Properties store, then onOpen could get the user email address from there instead of using Class Session. Related question: Determine current user in Apps Script

Algorithm

onOpen will be executed every time the owner or an editor, any editor, opens the spreadsheet no matter if another user is active, so if brs@test.com opens de the spreadsheet and few moments later amw22test.com do the same, the first user will see all the sheets.

Maybe instead of using one spreadsheet for all users you should create one spreadsheet for each group and one master spreadsheet for the admin group.


Other related questions


Post a Comment for "Hiding Worksheets From Specific Users Inside A Spreadsheet"