WD6X: AppleScript Example: MacScript and MacScript$()

Last reviewed: February 5, 1998
Article ID: Q119887
The information in this article applies to:
  • Microsoft Word for the Macintosh, version 6.0, 6.0.1, 6.0.1a

SUMMARY

This article contains an AppleScript example that demonstrates the use of the following WordBasic statement and function:

   MacScript
   MacScript$()

This article supplements the information in online Help. To open this Help topic, choose the Help button on your keyboard, select the Programming With Microsoft Word option, and type "macscript" (without quotation marks) on the query line.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

MORE INFORMATION

Syntax

MacScript Script$

MacScript$(Script$)

   Script$ is the path and filename of a script or a text string that will
   be compiled and run by AppleScript.

The MacScript statement runs an existing AppleScript script or passes a text string to AppleScript that will be interpreted by AppleScript.

The MacScript$() function behaves the same as the MacScript statement and also returns the value returned by Script$. The MacScript$() function always return a string. If the script specified by Script$ returns anything other than a string, it is converted to a string by MacScript$(). If the script specified by Script$ does not return a value, the MacScript$() returns the empty string("").

In Windows, the MacScript statement and MacScript$() function are not available and generate errors.

Example

The following macro refers to a script called CalculateString. Suppose that this script takes the selected string in a Word document and sends it to Microsoft Excel, where Microsoft Excel tries to evaluate the string as a formula. If Microsoft Excel can evaluate the formula, the script returns the value to Word as a string. The WordBasic macro can then replace the selection with the contents of result$.

   Sub MAIN:
      result$ = MacScript$("HD:APPLESCRIPT:SCRIPTS:CALCULATESTRING")
      If result$ <> "" Then
         EditCut
         Insert result$
      End If
   End Sub

REFERENCES

"Microsoft Word Developer's Kit," version 6.0, Microsoft Press, 1994, Appendix D, "AppleScript"


Additional query words: word basic
Keywords : kbmacroexample macword word6 kbmacro
Version : MACINTOSH:6.0,6.0.1,6.0.1a
Platform : MACINTOSH
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.