I have an Excel VBA project that makes heavy use of Windows Scripting Dictionary objects. I recently had a user attempt to use it on a Mac and received the following error: Compile Error: Can't find. Excel for the Mac Tips. In July 2011, I started working with Office 2011 on my first Mac computer. My idea is to go through all my Excel for Windows tip pages and see if I can also get the VBA code working in Mac Excel. It is very diffecult to make code that will work in every Mac Excel version.
-->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.
VBA is supported in Excel 2011 (the current version) and all previous editions except Excel 2008 on the Mac. Numbers is a very simple spreadsheet program provided by Apple.Numbers has no support for VBA. The Numbers interface is simple and attractive, but its capabilities are minimal. The mac version of Excel supports.xlam.xlsb so your projects can be made to work cross platform. To automate a repetitive task so that you can do the task again with a single click, you can use the Developer tab in Excel for Mac to record and run a macro. You can also create a macro by using the Visual Basic Editor in Microsoft Visual Basic for Applications (VBA) to write your own macro programming code.
The following code shows how to call AppleScriptTask from VB.
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:
- com.microsoft.Word
- com.microsoft.Excel
- com.microsoft.Powerpoint
For example, the corresponding AppleScript for Excel would be in a file named
MyAppleScriptFile.applescript
that is in ~/Library/Application Scripts/com.microsoft.Excel/.Important
The folders such as
com.microsoft.Excel
may not exist. In that case, just create them by using a standard mk dir command.The following is an example of a handler.
Vba Macro For Sending Email From Excel
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.
-->Use VBA add-ins and macros that you developed for Office for Windows with Office for Mac.
Applies to: Excel for Mac | PowerPoint for Mac | Word for Mac | Office 2016 for Mac
If you are authoring Macros for Office for Mac, you can use most of the same objects that are available in VBA for Office. For information about VBA for Excel, PowerPoint, and Word, see the following:
Note
Outlook for Mac and OneNote for Mac do not support VBA.
Office 2016 for Mac is sandboxed
Unlike other versions of Office apps that support VBA, Office 2016 for Mac apps are sandboxed.
Sandboxing restricts the apps from accessing resources outside the app container. This affects any add-ins or macros that involve file access or communication across processes. You can minimize the effects of sandboxing by using the new commands described in the following section.
Creating an installer or putting user content
For instructions on creating an installer for your add-in, please refer to the article here: Installing User Content in Office 2016 for Mac
New VBA commands for Office 2016 for Mac
The following VBA commands are new and unique to Office 2016 for Mac.
Command | Use to |
---|---|
GrantAccessToMultipleFiles | Request a user's permission to access multiple files at once. |
AppleScriptTask | Call external AppleScript scripts from VB. |
MAC_OFFICE_VERSION | IFDEF between different Mac Office versions at compile time. |
Ribbon customization in Office for Mac
Office 2016 for Mac supports ribbon customization using Ribbon XML. Note that there are some differences in ribbon support in Office 2016 for Mac and Office for Windows.
Ribbon customization feature | Office for Windows | Office for Mac |
---|---|---|
Ability to customize the ribbon using Ribbon XML | Available | Available |
Support for document based add-ins | Available | Available |
Ability to invoke Macros using custom ribbon controls | Available | Available |
Customization of custom menus | Available | Available |
Ability to include and invoke Office Fluent Controls within a custom ribbon tab | Available | Most familiar Office Fluent Control Identifiers are compatible with Office for Mac. Some might not be available. For commands that are compatible with Office 2016 for Mac, see idMSOs compatible with Office 2016 for Mac. |
Support for COM add-ins that use custom ribbon controls | Available | Office 2016 for Mac doesn't support third-party COM add-ins. |
idMSOs compatible with Office 2016 for Mac
For information about the idMSOs that are compatible with Office 2016 for Mac, see the following:
See also
Support and feedback
![Vba macros for accounting Vba macros for accounting](https://www.werden.download/wp-content/uploads/mzvzOm/visual-basic-editor-vba-updates-for-excel-for-mac-2016.jpg)
Vba For Machine Learning
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.