XL98: How to Pass a Cell Value to an AppleScript Variable (188664)



The information in this article applies to:

  • Microsoft Excel 98 Macintosh Edition

This article was previously published under Q188664

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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. 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:

184440 MacXL: How to Run VBA Procedures from AppleScript


Modification Type:MajorLast Reviewed:6/17/2005
Keywords:kbdtacode kbhowto kbProgramming KB188664