Activate cell depending on user online?

32 views
Skip to first unread message

Johan Kraaijeveld

unread,
May 23, 2020, 5:48:30 AM5/23/20
to Google Apps Script Community

I want to activate a cell depending on the user.
So user A must have a active cell (for his cursor) in A5, User B in E5 and so on.
How do I do that? The users are shared users

Clark Lind

unread,
May 24, 2020, 9:22:02 AM5/24/20
to Google Apps Script Community
You might be able to try getting the user onOpen. Then depending on the user, activate the appropriate cell. 
This assumes all users are on the same domain and have access to the sheet. This won't work where a user has not granted permission.

Something like this (I don't know if this will work or not, and going from memory, so excuse any errors): 

function onOpen() {
   var user = getUser();
   activateCell(user);

}

//From: Script services --> Base --> Session
function getUser() {
  var user = Session.getActiveUser().getEmail();
  return user;
}

function activateCell(user) {
 var cell;
//maybe use a switch depending on how many users there are
   switch (user) {
        case "us...@gmail.com" :
        cell = "A1";
        break;

       case  "us...@gmail.com":
       cell = "E5"
   }
   var ss = SpreadsheetApp... etc etc  //get the spreadsheet, get the sheet
   ss.getRange(cell).activate;
}

This, or a similar approach is how I would attempt it. I hope that helps!

Johan Kraaijeveld

unread,
May 24, 2020, 4:25:47 PM5/24/20
to google-apps-sc...@googlegroups.com
Hey Clark,

thanks for your reply on this.
I think i'm close to a solution, but i need your help i think.
I'm getting the user on Onopen() but when a leg of darts is finished i have to reset the cursor.
If I run the function opopen wich I changed in Cursor() it is getting the user after a cell is clicked or so.
Only then i can reset the cell activation.
I put the script below and appreciate if you can help?
th Johan

function cursor() {

   var user = getUser();
   activateCell(user);
   Logger.log(user)


}

//From: Script services --> Base --> Session
function getUser() {
  var user = Session.getActiveUser().getEmail();
  Logger.log(user)
  return user;
}

function activateCell(user) {
   var spreadsheet = SpreadsheetApp.getActive();
     var first = spreadsheet.getSheetByName("x01");  //activeert de andere sheet

   
 var cell;
//maybe use a switch depending on how many users there are
   switch (user) {
        case "naal...@gmail.com" :
        cell = "I5";
      first.getRange(cell).activate;
      Logger.log(cell)
        break;

     case("johan.kr...@gmail.com"):
       cell = "E5";
       first.getRange(cell).activate;
       Logger.log(cell)
       break;
       }
   

     
   
}  

Op zo 24 mei 2020 om 15:22 schreef Clark Lind <cwl...@gmail.com>:
--
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/af320a1d-decc-4a3c-a680-8e1511e96475%40googlegroups.com.


--
Met vriendelijke groet,

Johan Kraaijeveld
0031655888484
Reply all
Reply to author
Forward
0 new messages