Re: Contents of an Excel cell
Re: Contents of an Excel cell
- Subject: Re: Contents of an Excel cell
- From: John W Baxter <email@hidden>
- Date: Thu, 18 Apr 2002 21:08:48 -0700
At 9:59 -0700 4/17/2002, Paul Berkowitz wrote:
>
On 4/17/02 9:25 AM, "Christopher Coulon" <email@hidden> wrote:
>
>
> I am scripting an Excel worksheet and need to test the contents of a cell to
>
> stop a repeat loop, but I can't seem to find the AS expression to get the
>
> contents of an given cell. Is there a line that will return the value of
>
> "R3:C3" so that I can tell if its numeric value is greater than zero?
>
>
>
> set myCell to contents of "R3:C3"
>
>
>
> or
>
>
>
> set myCell to value of "R3:C3"
>
>
>
> don't work.
>
>
>
>
set myCell to Value of Cell "R3C3" of ActiveSheet
>
>
>
[no colon in name, and you have to specify the element type 'Cell']. It will
>
work without 'of ActiveSheet' too, but it's better to be unambiguous.
>
>
Be aware also that:
>
>
1) an empty cell returns value of 0
>
>
2) a cell with numeric value of 0 returns 0.0: numeric values are always
>
reals, not integers. So you'll have to check:
>
>
try
>
if myCell > 0.0 then
>
--whatever
>
end if
>
on error
>
beep -- or something else in case value is blank or string
>
end try
>
>
>
>
3) to SET the value of a cell to empty, you have to set it to "", not 0
>
!
Speaking about Microsoft Excel X and Mac OS X 10.1.4 with Applescript
1.8.2b3 here, note that you can get the as-formatted cell contents using
text of cell "...". But, at least in my simple test, the Value is
returning 0 when it shouldn't: the actual value is 2.7773992 but this
script
tell application "Microsoft Excel"
{text of Cell "R3C3" of ActiveSheet, Value of Cell "R3C3" of ActiveSheet}
end tell
returns {"$2.78 ", 0}
(and the Value of ... stuff alone also returns 0). 0 seems like an
unreasonable rounding of 2.7773992, whether as taught in school or learned
out behind the barn. ;-)
It's interesting to me that Microsoft has managed to get the terminology
"text" back from Apple in the above context. Back in 1993, that
terminology was in Excel when AppleScript was released...and the underlying
code worked from Frontier...but Apple's "text" took precedence over
Excel's. I hacked my Excel's 'aete' to change the terminology for the
four-byte code MS had used, but never released the result because of
copyright concerns and the fact that I picked some really poor multi-word
terminology and was too lazy to pick something better.
--John
--
John Baxter email@hidden Port Ludlow, WA, USA
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.