VBA on a Mac: Excel macros in Excel for Mac

Excel for Mac comes with VBA and the Visual Basic Editor, and most macros written on Windows run on it. A few things do not, and the Mac asks for permission in places where Windows stays quiet. This page shows you where to find the editor, what behaves differently and how to track down a macro that will not run on your Mac.

In short: yes, VBA works in Excel for Mac. Open the editor from Developer > Visual Basic or press Option+F11. Most of the language and the Excel objects are the same as on Windows. The main differences: no ActiveX controls, no calls into Windows libraries with Declare, and file access that the user has to approve. Excel for the web and Excel on iPad do not run macros at all.

Does VBA work on a Mac?

Yes. According to Microsoft, macros for Office for Mac can use most of the objects that VBA offers on Windows. That covers Excel, Word and PowerPoint for Mac; Outlook and OneNote for Mac have no VBA. You do not need an extra license, since VBA is built into the desktop versions of Excel.

Excel versionCan you write and run macros?
Excel for WindowsYes
Excel for MacYes, with the differences listed below
Excel for the webNo. You can open and edit a workbook that contains macros, and they stay in the file, but they do not run. Open in Desktop App takes you back to Excel on your Mac or PC.
Excel for iPad and iPhoneNo

Show the Developer tab and open the VBA editor

The Developer tab is hidden until you switch it on:

  1. Choose Excel > Preferences > Ribbon & Toolbar.
  2. Under Customize the Ribbon, look at Main Tabs and tick Developer.
  3. Click Save and close Preferences. On the Developer tab, Visual Basic opens the editor and Record Macro starts the recorder.

The keyboard is quicker. If a function key changes the volume or brightness instead, hold Fn as well.

ActionWindowsMac
Open the Visual Basic EditorAlt+F11Option+F11
Show the Macro dialogAlt+F8Option+F8

In the editor you insert a module and type your macro, exactly as in VBA basics. Save the workbook as .xlsm; a plain .xlsx file cannot keep macros.

What is different from Windows

Since Office 2016 for Mac, Excel, Word and PowerPoint run in a sandbox. Microsoft describes this as a restriction on reaching resources outside the app, which mostly affects macros that work with files or talk to other programs.

AreaOn a MacWhat to do
ActiveX controls (buttons, check boxes and so on from the ActiveX list)Not supported. Microsoft says the Mac and web versions do not support them, and Microsoft 365 and Office 2024 switch them off by default on Windows too.Run macros from the Macro dialog (Option+F8) or with the shortcut key you set when recording.
Declare statementsThey call procedures in a DLL. Microsoft's own examples use Windows libraries such as User32, so this kind of code is written for Windows.Keep separate code paths with #If Mac Then … #Else … #End If.
COM add-insOffice for Mac does not support third-party COM add-ins.Use the add-in on Windows, or do the job in plain VBA.
Reading and writing filesThe first time a macro touches a file, Excel asks the user for permission. So a macro that opens files cannot run unattended.GrantAccessToMultipleFiles asks once for a whole list of files. Excel remembers the answer.
Talking to other appsMacScript is deprecated and, because of the sandbox, cannot drive other apps such as Finder.AppleScriptTask runs an AppleScript stored in ~/Library/Application Scripts/com.microsoft.Excel/.
File pathsPaths look like /Users/jordan/Documents/export.csv, while Windows uses C:\Users\Jordan\Documents\export.csv.Do not hard-code them. Build them from ThisWorkbook.Path and Application.PathSeparator, the character that separates folder names.
Sub PathNextToWorkbook()
    Dim filePath As String
    filePath = ThisWorkbook.Path & Application.PathSeparator & "export.csv"
    MsgBox filePath
End Sub

Sub WhichSystem()
    #If Mac Then
        MsgBox "Running in Excel for Mac"
    #Else
        MsgBox "Running in Excel for Windows"
    #End If
End Sub

Mac is a compiler constant that VBA defines for you: True on a Mac, False everywhere else. Only the matching branch is compiled, which is how one workbook can carry Windows-only lines and still run on a Mac.

Dictionary or Collection?

Our Dictionary and Collection lesson creates its dictionary with CreateObject("Scripting.Dictionary"). That object is not part of VBA itself; it comes from the Microsoft Scripting Runtime library. A Collection, on the other hand, is built into the language (Dim c As New Collection) and needs nothing else. If a macro has to run on Windows and Mac alike, test any Dictionary code on the Mac before you rely on it. Collection is the option without an outside dependency.

Excel macros not working on a Mac? Check these

  1. Security setting: Excel > Preferences > Security. The default, Disable all macros with notification, asks you each time a workbook with macros opens. With Disable all macros without notification, nothing runs and nothing asks. Microsoft advises against Enable all macros unless you are sure no harmful files will come your way. Enable macros explains the warnings in more detail.
  2. File type: only .xlsm workbooks hold macros. If someone saved the file as .xlsx, the code is gone.
  3. ActiveX buttons: if the macro was wired to an ActiveX button, that button does not work on a Mac. Start the macro from the Macro dialog with Option+F8.
  4. Windows-only code: Declare lines that point at Windows libraries need a separate Mac branch (see #If Mac Then above).
  5. File access: when the macro opens a file for the first time, Excel asks for permission. Without your OK, the macro cannot reach the file.
  6. Wrong app: Excel for the web and Excel on iPad never run VBA. Open the file in the desktop app.

Learning VBA on a Mac

The exercises on this site do not run in your copy of Excel. Your code goes to our server, which runs it in a re-creation of VBA with its own workbook, and the result comes back to your browser. So it makes no difference whether you are on a MacBook, a Windows PC or an iPad, and your macro security settings do not get in the way. Try one now:

Task Write a macro CopyValue that copies the contents of A2 to B2. Check also tests it with different text in A2.

ABCD
1OriginalCopy
2Invoice 1043
3
4
5

The VBA course takes you from your first line of code to finished reports this way. Dictionary and Collection both work in the exercises on any device, because the code runs on the server. For free experiments there is the online VBA editor, and if you are weighing VBA against Python or Office Scripts, see VBA vs Python.

FAQ

Is there a VBA editor in Excel for Mac?

Yes. Open it with Developer > Visual Basic or Option+F11. If you do not see the Developer tab, switch it on under Excel > Preferences > Ribbon & Toolbar.

Will my Windows macros run on a Mac?

Most will. Microsoft says the Mac offers most of the same objects as VBA on Windows. The usual trouble spots are ActiveX controls, Declare calls into Windows libraries, COM add-ins and hard-coded Windows paths.

Can I run macros on an iPad?

No. Excel for iPad and iPhone does not run VBA, and neither does Excel for the web. You can still learn VBA on an iPad here, because the exercises run in the browser.

Why does Excel for Mac keep asking about file access?

Excel for Mac runs in a sandbox, so it needs your permission before a macro may open a file outside the app. It asks the first time each file is used. GrantAccessToMultipleFiles lets you ask for several files in one go.

Up next: the VBA course

Short lessons with exercises that run in the browser, from your first macro to a finished monthly report. Works the same on a Mac as on a PC.

Start the VBA course

Write to us

Choose language

Select your preferred language