Calling a custom function in apple script from a cell in Excel 2008

S

sgeffert

I have used VBA to write a few custom functions that can simply be
called like =Tsat("H2O",K10*100,"kPa") in side a cell. But since the
upgrade to Excel 2008 where they dropped VBA< I am having to rewrite
these functions in applescript. An example of one such function is
this:

-- Function Tsat: Calculates the Saturation Temperature of a given
substance at a specific pressure x
on Tsat(substance, x, units)
tell application "Microsoft Excel"
set xColumn to "C"
set xRange to ("C11:C70")

--find the row closest to x
set the value of cell ("T74") to "=match(" & x & "," & substance &
"!" & xRange & ", 1) + 10"
set xRow to the value of cell "T74"
set the value of cell "T74" to ""
--x is the saturation pressure
set x1 to the value of cell (xColumn & ((xRow - 1) as integer)) of
sheet (substance)
display dialog (x1)
set x2 to the value of cell (xColumn & (xRow as integer)) of sheet
(substance)
set x3 to the value of cell (xColumn & ((xRow + 1) as integer)) of
sheet (substance)
--y is the saturation temperature
set y1 to the value of cell ("B" & ((xRow - 1) as integer)) of sheet
(substance)
set y2 to the value of cell ("B" & (xRow as integer)) of sheet
(substance)
set y3 to the value of cell ("B" & ((xRow + 1) as integer)) of sheet
(substance)
set diff1 to x2 - x1
set diff2 to x3 - x2
set a to (((y3 - y2) / diff2) - ((y2 - y1) / diff1)) / (diff1 +
diff2)
set B to ((diff1 - 2 * x2) * ((y3 - y2) / diff2) + (diff2 + 2 * x2)
* ((y2 - y1) / diff1)) / (diff1 + diff2)
set c to (x2 * (x2 - diff1) * ((y3 - y2) / diff2) - x2 * (x2 +
diff2) * ((y2 - y1) / diff1) + y2 * (diff1 + diff2)) / (diff1 + diff2)
set y to c + B * x + a * x * x

set Tsat to y

return Tsat
end tell
end Tsat

Can someone enlighten me on how this is to be called from a cell in
excel in order to produce results upon completion of execution from
the system script menu?

Thank you.

Sean
 

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