Select and Zoom to a Range in Excel for the Web with Office Scripts
Question details
The user wants to select a range and zoom to it using Office Scripts in Excel for the web.

- Product
- Microsoft Excel for the web and Office Scripts
- Device & OS
- not provided
- Scenario
- Reproduce Excel's Select and Zoom commands for a specified range in a web-based workbook.
- Observed behavior
- Office Scripts can select a range, but it has no direct equivalent to ActiveWindow.Zoom or a command to zoom to the selected range.
Open the workbook in Excel for the web and identify the worksheet and range you want to select. Check that the Automate tab is available so you can create and run an Office Script.
Select the range with an Office Script and adjust zoom manually
Use this approach when you need a script to select a range, followed by a manual zoom adjustment.
Office Scripts can select cells, but it does not expose an equivalent to VBA's ActiveWindow.Zoom or a command that automatically fits the selected range to the window.
In Excel for the web, open the workbook and choose Automate > New Script.
Replace the editor contents with: function main(workbook: ExcelScript.Workbook) { const worksheet = workbook.getActiveWorksheet(); worksheet.getRange("F6:L15").select(); } Change F6:L15 to the range you need.
Activate the intended worksheet, then click Run in the script editor. The script selects the specified range on that worksheet.
Use Excel's zoom controls if available, or open your browser's menu and adjust Zoom until the selected range is easy to see. Browser zoom changes the whole page and does not automatically fit the selection.

View Excel Workbooks in WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and Microsoft Excel format compatibility, making it easy to move existing workbooks. It does not run or fix Microsoft Office Scripts.

Frequently Asked Questions
Can Office Scripts zoom to the selected range?
No. Office Scripts can select a range with getRange(...).select(), but it does not provide a command to zoom the view to that selection.
How do I select a range on a specific worksheet?
In Automate > New Script, use workbook.getWorksheet("Sheet1").getRange("F6:L15").select(), replacing the sheet name and range with your own.
How can I change the zoom in Excel for the web?
Use Excel's zoom controls if they are available, or adjust Zoom from your browser menu. Browser zoom affects the entire page rather than fitting only the selected cells.
Will an Office Script run in WPS Spreadsheet?
No. Office Scripts are a Microsoft Excel feature. WPS Spreadsheet can open XLSX workbooks, but it does not run Office Scripts.




