Microsoft KB Archive/114648

= Microsoft Knowledge Base =

Excel: Returning Data to AppleScript from Macro
Last reviewed: September 12, 1996

Article ID: Q114648

The information in this article applies to:


 * Microsoft Excel for the Macintosh, version 4.0

SUMMARY
When you run a Microsoft Excel macro from AppleScript, you can return a result to the script.

Providing AppleScript with Status Information or the Result from a Macro
To provide AppleScript with status information or the result from a macro, do the following:


 * 1) Save the value in a cell or defined name which can be interrogated later by AppleScript.
 * 2) Include a message in the RETURN function of the macro.

Getting Status Information Saved in Cell or Defined Name
To get status information saved in a cell or as a defined name, interrogate the cell or defined name from within the script that called the macro.

  Interrogating a cell. Assuming a value was stored in cell B1 of the active sheet, the following script segment will retrieve the value in that cell: set myresult to value of cell "R1C2"   Interrogating a defined name. Assuming a value was stored in the defined name called "XLResult," the following script segment will retrieve the value of that defined name: set myresult to value of Range "XLResult" 

Sample Macro
The macro below demonstrates how Microsoft Excel returns a message to AppleScript. The macro creates a window, sizes, and then moves the window around the screen. Upon completion, the macro then sends the message "Macro completed" to AppleScript via the RETURN function.

Testscript =NEW(1) =SET.NAME("window_name",GET.DOCUMENT(1)) =WINDOW.SIZE(200,200,window_name) =FOR("x",1,30) =   WINDOW.MOVE(x*5,x*5,window_name) =NEXT =FOR("x",31,60) =   WINDOW.MOVE(x*5,300-(x*5),window_name) =NEXT =RETURN("Macro completed.") NOTE: The RETURN function MUST return a value. If a value is not supplied, an error will be generated in AppleScript. If you don't want to return a value, you can return a null value by using the following function to terminate the macro:

=RETURN("") Microsoft provides macro examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This macro is provided 'as is' and Microsoft does not guarantee that the following code can be used in all situations. Microsoft does not support modifications of the code to suit customer requirements for a particular purpose.