In our app, the end user exports a file and it's then automatically opened
in Excel. I'd prefer being able to do this without any end user
intervention/configuration. So if the script was able to work for either X
or 2004 that would be dynamite!
After opening Excel 2004 and your Script Editor, open the compiled script
(or script application) - NOT a text-only version - that you used to use in
Excel X or earlier. You'll see that most of the old commands in Excel tell
blocks have been replaces by raw codes, like this:
set ur to «class PURG» of «class PASH»
«event XCELBSFT» every column of ur
That's fine. (If this is a NEW script which doesn't yet exist in an Excel X
version, you need to quit Script Editor, quit Excel 2004, log out (Apple
menu) log in, open Excl X, open Script Editor, and write your script. To
"transfer" an Excel X script to Excel 2004 or vice versa, first save a copy
of the script As Text. Then after doing the log in/out stuff, open the text
(.applescript or .txt) version while in the other Excel. That way you see
the English-language terminology which you replace with the new version. But
that's NOT what we're doing here. Here I'm assuming you already have both
versions of the script, and you should open the compiled X script while 2004
is open, to see the «raw codes».)
In your 2004 script, preface this to the very top (under any property and
global declarations you might have):
tell application "Microsoft Excel" to set theVersion to version as
string
set AppleScript's text item delimiters to {"."}
set mainVersion to (text item 1 of theVersion) as integer
set AppleScript's text item delimiters to {""}
if mainVersion < 11 then
-- paste your entire X version of the script, complete with «raw
codes»
else
-- continue with entire 2004 version
end if
That should compile OK, and run in either version. It will work best if the
user opens Excel first, before running the script. It should even work for
you with either version of Excel open. BUT - if you want to run it from
Script Editor, you'll first have to quit it and log out/in, open Excel and
Script Editor before switching to the version you have not been using
already.
If you're script is long, you might prefer to put each version on a handler
and just call the appropriate handler in each branch of the if/else block
above: it makes no difference.
Things could get peculiar if you try to run the script when you have more
than one version of Excel on your computer and you don't have either one
open. It shouldn't be a problem if the user has only one Excel. But it's
smoothest to open an Excel before running the script.
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <
http://www.entourage.mvps.org/faq/index.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 Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.