XL98: How to Pass a Cell Value to an AppleScript Variable

ID: Q188664

The information in this article applies to:

SUMMARY

This article includes a sample AppleScript script that demonstrates how to set a variable in your script to a value in a Microsoft Excel worksheet cell.

MORE INFORMATION

Microsoft provides programming 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

AppleScript is manufactured by Apple Computer Inc., a vendor independent of Microsoft; we make no warranty, implied or otherwise, regarding this product's performance or reliability.

The following steps demonstrate how to set an AppleScript variable to value stored in an Excel worksheet:

1. Start the Script Editor from the HD:Apple Extras:AppleScript folder.

2. Type the following into the script window (lower pane):

      tell application "Microsoft Excel"
   
         -- Activates Microsoft Excel.
         Activate
   
         -- Assigns the value of cell A1 to the variable myvar.
         copy Value of Cell "A1" to myvar
   
         -- Displays a dialog box with the value of myvar.
         display dialog myvar
   
         -- Assigns the value of myvar to cell B1.
         set Value of Cell "B1" to myvar & " test"
   
      end tell

3. On the File menu, click Save.

4. Type a name for your script and click Save.

5. Start Microsoft Excel.

6. Enter any text into cell A1 of Sheet1.

7. Leave Excel running and click Script Editor on the Application menu

   (in the upper-right corner of the screen).

8. Run your script.

   A dialog box will display the value you typed into cell A1.

9. Click OK.

   The value you typed into cell A1 will now appear in cell B1 with "test"
   appended to it.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q184440
   TITLE     : XL98: How to Run VBA Procedures from AppleScript

Additional query words: XL98
Keywords          : kbprg kbdta kbdtacode xlmac 
Version           : MACINTOSH:98
Platform          : MACINTOSH
Issue type        : kbhowto

Last Reviewed: May 18, 1999