Select Active Cell for specific user on a timer

141 views
Skip to first unread message

Christopher Cox

unread,
Sep 14, 2022, 5:32:08 AM9/14/22
to Google Apps Script Community
Hi,

I currently have a script which does a bunch of stuff before selecting the active cell of the user to a specific cell on multiple sheets. When running the script via a button, it works perfectly with no issue for the user that clicked the button.

I'm now trying to adapt it to run at a specific time each day on a time trigger for the same user. At the time of the trigger, the rest of the script runs but the active cell is not changed to the desired cell.

Relevant part of the script below:

function ResetActiveCell(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var Sheet = ss.getSheetByName("X");

  var ClearSheet = Sheet.getRange("A3:A");

  ClearSheet.clearContent();

  var setcell = Sheet.getRange("A3");

  Sheet.setCurrentCell(setcell);}


I've seen a couple of things around but nothing has worked so far, the closest thing that looks like it could work, replacing the bottom 2 lines from the script above is shown below but I can't get it to work. Any help would be massively appreciated!

function onOpen() {
   var user = getUser();
   activateCell(user);
   Logger.log(user)
}

function getUser() {
  var user = Session.getActiveUser().getEmail();
  Logger.log(user)
  return user;
}

function activateCell(user) {
   var spreadsheet = SpreadsheetApp.getActive();
     var first = spreadsheet.getSheetByName("X");

 var cell;
   switch (user) {
        case "c..@hotmail.com" :
        cell = "A3";
      first.getRange(cell).activate;
      Logger.log(cell)
        break;
       }
}  

Kind regards,
Reply all
Reply to author
Forward
0 new messages