Can Revolution communicate with Excel?

Ken Ray kray at sonsothunder.com
Fri Mar 18 01:56:09 EST 2005


On 3/17/05 7:06 PM, "Stgoldberg at aol.com" <Stgoldberg at aol.com> wrote:

> Wow! I'm a new user and really impressed with how quick (and accurate) my
> first question was answered.   I thank everyone who answered. Perhaps someone
> can 
> also answer the following:   Is there any way in which data (e.g. a number)
> calculated at in a Revolution stack can be automatically transferred to a
> given 
> cell (field) in an Excel program?   Thanks again.

Here's the way to do it for Mac. The basic script for AppleScript is like
this:

  tell application "Microsoft Excel"
    set value of cell "B3" to 500
  end tell

To translate this to Revolution, you'd do this (I use a q() function for
quoting data that makes it easier to work with):

on mouseUp
  SendToXL "500","B3"
end mouseUp

on SendToXL pWhat,pCell
  put "tell app" && q("Microsoft Excel") & cr & \
    "set value of cell" && q(pCell) && "to" && q(pWhat) & cr & \
    "end tell" into tScript
  do tScript as AppleScript
end SendToXL

function q pWhat
  return quote & pWhat & quote
end q

----------

Here's the way to do it for Windows. The basic VB Script code looks like
this:

  Dim ObjXL
  Set ObjXL = GetObject(,"Excel.Appliction")
  ObjXL.Range("B3").Value = "500"

To translate this to Revolution, you need to output this to a .vbs file and
"run" it, and then delete it when you're done. Here's how:

on mouseUp
  SendToXL "500","B3"
end mouseUp

on SendToXL pWhat,pCell
  put "Dim ObjXL" & cr & \
    "Set ObjXL = GetObject(," & q("Excel.Application") & ")" & \
    "ObjXL.Range(" & q(pCell) & ").Value =" && q(pWhat) into tScript

  -- Put the script into a file on disk
  put "C:\VBSTemp.vbs" into tFile
  put tScript into url("file:" & tFile)

  -- Run the file
  set the hideConsoleWindows to true
  get shell("cscript.exe //nologo" && tFile)

  -- Now, delete the file; best way is to give it 1 second to complete
  -- before deleting, so I'll use the "send in <time>" method to
  -- do this:
  send "delete file" && q(tFile) to me in 1 second
end SendToXL


If you're developing cross-platform, you can merge them into the same
handler by checking "the platform":

on SendToXL pWhat,pCell
  switch (the platform)
    case "MacOS"
      -- put the Mac code here
      break
    case "Win32"
      -- put the Windows code here
      break
  end switch
end SendToXL

Hope this helps,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list