The Microsoft Excel topics consist of typical and popular subroutines (macros) in Visual Basic for Applications (VBA), and their equivalents in AppleScript.
If you are testing scripts in Macintosh Script Editor, you may want to begin every one with an activate command on its own line just inside the
tell
application "Microsoft Excel"
block, as its first line. That will bring Excel
to the front so that you can see what is happening. It is not necessary to include activate when running saved scripts from the Script menu while Excel
is in the front (and there may be other occasions when you are running a script from elsewhere and don't want Excel
to come to the front). The activate parameter is not included in the sample scripts in these topics, but you may want to use it.
Before starting to script in Excel, it is a good idea to read the "Using the Excel
Dictionary" section (especially the "How to reference cells and ranges" topic) in the Microsoft Excel 2004 AppleScript Reference
(http://download.microsoft.com/download/3/A/7/3A70FB4B-0C6A-43E3-AAB7-AC9166B25632/Excel2004AppleScriptRef.pdf).
Although it is largely aimed at AppleScripters who are unfamiliar with the Excel
object model rather than vice versa, it is full of useful knowledge for all scripters of Excel.
Excel is one of the most complex and detailed applications there is, with a huge variety of capabilities. These topics offer AppleScript translations of short commands of various types to illustrate a wide variety of techniques, such as you might find in various combinations in many macros. They should be of help in many different situations and lead you on to other areas of the AppleScript dictionary.
Most of the enormous repertoire of Excel features as programmed through VBA have a straightforward equivalent in AppleScript. But here and there are methods or properties that have not made it over, or not in the same format. Solutions and workarounds are offered when these arise.
In particular, although the AppleScript implementation of Excel has been very thoroughly carried out, such that almost all of the VBA model can be found mirrored in the AppleScript model, there are peculiarities with columns and rows. For more information, see the Known issues in Excel 2004 topics.
One significant gap in the AppleScript model is that worksheet functions did not make it over from VBA. Apparently there are conflicts between how Excel performs these and how they would have to be done in AppleScript, which does not have the same precision with floating point numbers. But you can enter any function (via AppleScript) into a cell on a worksheet, let Excel do its calculations, pass the result (cell value) back to the script, and clear the cell.


