Navigating in Excel with AppleScript

T

TomMxEdit

I am new to Applescript and am trying to write a script to type text, move 1 cell to the right, type some more text in the new cell, etc. When I record my script using the AppleScript editor, the reference to the second and subsequent cells are to absolute cells on the sheet. How do I move in a relative fashion from the ActiveCell where I start rather than jumping to an absolute location on the sheet? In Visual Basic, I would use the "offset" command, but I don't see anything like this in AppleScript dictionary for Excel

Tom Carlson
 
P

Paul Berkowitz

I am new to Applescript and am trying to write a script to type text, move 1
cell to the right, type some more text in the new cell, etc. When I record my
script using the AppleScript editor, the reference to the second and
subsequent cells are to absolute cells on the sheet. How do I move in a
relative fashion from the ActiveCell where I start rather than jumping to an
absolute location on the sheet? In Visual Basic, I would use the "offset"
command, but I don't see anything like this in AppleScript dictionary for
Excel.


Yes, there is an Offset command in the Table Suite of the dictionary. Maybe
you didn't look in the Table Suite?

I haven't got Excel X here at the moment to test with, but wouldn't
something like this work?

tell application "Microsoft Excel"
set nextCell to Offset (get ActiveCell) ColumnOffset 1
set Value of nextCell to "Whatever you want"
end tell

Which would be best. Or you could do it the "conventional" AppleScript way:


tell application "Microsoft Excel"
set r to Row of ActiveCell
set c to Column of ActiveCell
set nextCell to Cell ("R" & r & "C" & (c + 1)) of ActiveSheet
set Value of nextCell to "Whatever you want"
end tell

Optionally you could change the focus:

set ActiveCell to nextCell

If you wanted to _add_ text to what was already there:

set theContent to Value of nextCell
set Value of nextCell to (theContent & " whatever else you want")


--
Paul Berkowitz
MVP Entourage
Entourage FAQ Page: <http://www.entourage.mvps.org/toc.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Entourage you are using - 2001 or X.
It's often impossible to answer your questions otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top