I would like to write a script that I can apply to a shared sheet that automatically changes the zoom level of the sheet (not the browser window) to 75% when the sheet is opened.
The script that I cobbled together has it's own issues with deprecated UserProperties commands that I'm trying to fix on the side, but adding the function to alter the zoom would be very helpful in the mean time while I work that out. Any help afforded would be greatly appreciated!
Mark
Current script is below: This is used to choose the last modified sheet, and navigate to that cell (clunkily:
function setTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger("myFunction").forSpreadsheet(ss).onEdit().create();
}
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var sName = sheet.getName();
var currentCell = sheet.getActiveCell().getA1Notation();
Utilities.sleep(1000);
UserProperties.setProperty("mySheetName", sName).setProperty("mySheetName", sName);
Utilities.sleep(1000);
UserProperties.setProperty("myCell", currentCell);
Utilities.sleep(1000);
}
function onOpen() {
var lastModifiedSheet = UserProperties.getProperty("mySheetName");
Utilities.sleep(1000);
var lastModifiedCell = UserProperties.getProperty("myCell");
Utilities.sleep(1000);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(lastModifiedSheet).getRange(lastModifiedCell).activate();
}
At this time the Google Apps Script Spreadsheet Service (Class SpreadsheetApp) either the Base Service Ui Class haven't a method to change the spreadsheet zoom.
As of January 2025, Google Apps Script still doesn't include a method to handle the spreadsheet Zoom.
Reference