Run an AppleScript with VB

Call an AppleScript file from a VB macro in Office 2016 for Mac.

Applies to: Excel for Mac | PowerPoint for Mac | Word for Mac | Office 2016 for Mac

The AppleScriptTask command executes an AppleScript script file located outside the sandboxed app.

The following code shows how to call AppleScriptTask from VB.

    Dim myScriptResult as String
    myScriptResult = AppleScriptTask ("MyAppleScriptFile.applescript", "myapplescripthandler", "my parameter string") 

The MyAppleScript.applescript file must be in ~/Library/Application Scripts/[bundle id]/. The .applescript extension is not required; you can also use the .scpt extension.

Myapplescripthandler is the name of a script handler in the MyAppleScript.applescript file.

My parameter string is the single input parameter to the myapplescripthandler script handler.

The following are the [bundle id] values for Excel, PowerPoint, and Word:


For example, the corresponding AppleScript for Excel would be in a file named MyAppleScriptFile.applescript that is in ~/Library/Application Scripts/


The folders such as may not exist. In that case, just create them by using a standard mk dir command.

The following is an example of a handler.

    on myapplescripthandler(paramString) 

    #do something with paramString 
    return "You told me " & paramString 

    end myapplescripthandler

What happened to MacScript?

Earlier versions of Office for Mac implemented a command called MacScript that supported inline AppleScripts. Although that command still exists in Office 2016 for Mac, MacScript is deprecated. Due to sandbox restrictions, the MacScript command cannot invoke other applications, such as Finder, in Office 2016 for Mac. We recommend that you use the AppleScriptTask command instead of the MacScript command in apps for Office 2016 for Mac.

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.