To bring a range into view, use the ‘go to…’ command. In Excel’s menus, it’s as I’ve written it but in applescript, it’s just goto
.
Here are a few ways to use it. Try this in a new workbook (make sure it has a ‘Sheet1’).
What it does is first name
a range. Named ranges are like variables but in Excel’s GUI. You can use them in formulas or in scripts. Typically you access them from the drop down to the left of the formula bar. By default, it doesn’t really look like a drop down but there is a double-arrow icon beside it. Normally, it displays the address of the active cell but if you click on the double arrow, it will pop up a list of the workbooks’s named ranges (assuming you have any in the workbook).
Then it uses the goto
command along with the named range ‘corner’ to go there. The scroll
option puts the area in the upper left corner of the window.
Next, after a brief delay so you can see the action, it goes back to the upper left corner of the sheet using a standard range object.
Then it returns to the named range ‘corner’ but this time without the scroll option, so the selected range will likely appear in the bottom right corner of the window. It finishes by activating the second cell of the selected range.
tell application "Microsoft Excel"
activate
tell workbook 1
tell sheet "Sheet1"
set c99 to range "Sheet1!Y99:Z100"
set name of c99 to "corner"
goto reference "corner" with scroll
delay 2
set bleep to range "Sheet1!A1:F10"
goto reference bleep
delay 2
goto range "Sheet1!corner" -- this time without scroll
activate object cell 2 of range "Sheet1!corner"
end tell
end tell
end tell
So in your case, you can use the goto command to visit different zones of the sheet as needed. I would give the ‘safe zone’ range a name (although it is not obligatory) as it is the easiest way to work with ranges on a large sheet. As a bonus, you can also move to a different sheet using it and use it in Excel (outside of any script), for example with the Edit > Go To… command.
I forget where you decided to place the safe zone in your sheet but if for example it was the range “A1000:F1000” then here are three ways to use goto to bring that range into view:
Update: Added a fourth approach… activate object
set sz to range "Sheet1!A1000:F1000"
set name of range "Sheet1!A1000:F1000" to "safezone"
goto range "Sheet1!A1000:F1000" with scroll
goto reference sz with scroll
goto reference "safezone" with scroll
activate object range "A1000:F1000"