Yes—Microsoft Excel for Mac supports VBA, so you can create, edit, and run many Excel macros on a Mac. The main caveat is compatibility: VBA features that rely on Windows-only components, such as COM automation or ActiveX controls, may not work on macOS.
What VBA Does in Excel for Mac
VBA, or Visual Basic for Applications, is Excel’s built-in programming language for automating workbook tasks. A macro is a procedure written in VBA: it can format a report, process rows, create worksheets, or repeat a sequence of spreadsheet operations. You can run a macro manually, attach it to a button, or use it as part of a larger workbook workflow.
Excel for Mac includes a Visual Basic Editor (VBE) for writing and changing code. A macro-enabled workbook can also be shared with someone using Excel for Windows, provided the code uses features available on both platforms. VBA is not the same as a formula: formulas calculate values in cells, while VBA can carry out actions across a workbook or interact with Excel’s interface.
Excel for the web is different. It can open many macro-enabled workbooks and preserve their VBA content, but it cannot create, edit, or run VBA macros. To work with VBA, use the Excel desktop app for Mac or Windows.
How to Show the Developer Tab and Open VBA
The Developer tab gives you direct access to macro tools and the code editor. In current Excel for Mac versions, open Excel > Settings > Ribbon & Toolbar, select the main ribbon tab list, and enable Developer. In some older releases, the menu is named Excel > Preferences rather than Settings.
Once the tab is visible, choose Developer > Visual Basic to open the editor. You can also use the keyboard shortcut Option+F11; on some Mac keyboards, you may need to hold Fn as well. The Windows equivalent is Alt+F11. To open the macro list, use Developer > Macros or Option+F8 on Mac; the Windows shortcut is Alt+F8.
In the VBE, the Project Explorer lists open workbooks. Select the workbook where the code belongs, then use Insert > Module to add a standard code module. Procedures in a standard module are usually easy to run from the Macros dialog. Code can also be placed in a worksheet or workbook code module when it needs to respond to events, such as a change to a cell.
Create and Run a Simple Macro
For a straightforward first macro, suppose column A contains names starting in row 2 and you want column B to label each nonblank row. In the VBE, insert a module and add this procedure:
Sub MarkReviewed()
' Mark each row that has a value in column A.
Dim ws As Worksheet
Dim lastRow As Long
Dim r As Long
Set ws = ActiveSheet
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For r = 2 To lastRow
If Len(Trim$(CStr(ws.Cells(r, "A").Value))) > 0 Then
ws.Cells(r, "B").Value = "Reviewed"
End If
Next r
End Sub
This example uses the active worksheet, finds the last used row in column A, and writes Reviewed in column B for rows with a nonblank entry. It does not clear existing values in column B for blank rows. Before running any macro, save a copy of the workbook: macro actions generally cannot be undone with Ctrl+Z or Command+Z.
To run it, return to Excel, choose Developer > Macros, select MarkReviewed, and click Run. Check that the intended sheet is active first. If you want to run the macro from a worksheet button, add a button from Developer > Insert and assign the procedure. Button choices and their appearance can differ across Mac and Windows.
Saving a Workbook That Contains VBA
A workbook that contains VBA must be saved in a macro-enabled format if you want the code to remain in the file. Choose File > Save As, then select Excel Macro-Enabled Workbook (.xlsm) as the file format. The standard .xlsx format does not store VBA project code; if Excel warns that macros will be removed, cancel and choose .xlsm if you need to keep them.
Excel add-ins can also contain VBA. The .xlam format is commonly used for an Excel add-in, but a normal workbook project is usually easier to understand and share while you are learning. Store a working copy separately from the original data, and make sure collaborators know that macros are included. A macro-enabled file is not automatically trustworthy just because Excel can open it.
Mac and Windows VBA Compatibility
Many everyday Excel object-model operations work on both platforms: reading and writing cell values, formatting ranges, creating worksheets, and using workbook collections. Compatibility problems tend to appear when code depends on the operating system or on another program. A macro that only edits cells is generally a better candidate for cross-platform use than one that controls Windows applications or calls Windows system libraries.
- COM automation: Code that creates or controls Windows COM objects, such as some automation of other Microsoft or third-party desktop applications, is not a direct Mac equivalent.
- ActiveX: ActiveX controls and related Windows-specific techniques are not supported on Mac in the same way. A workbook built around them may need a different interface, such as a worksheet button or cell-based controls.
- Windows API calls: VBA declarations that call Windows DLLs will not simply work on macOS. Conditional compilation can separate platform-specific code, but each platform still needs a valid implementation.
- File and folder access: macOS privacy protections and Office’s sandbox can affect file operations outside the workbook’s permitted locations. Where appropriate, use Excel’s file-selection dialog or the Mac-specific
GrantAccessToMultipleFilesfunction to request access.
When a workbook is used on both Mac and Windows, test it in both desktop versions. Pay particular attention to file paths, external applications, controls, and any code that uses operating-system calls. A Windows path such as C:\Reports is not a Mac path, and replacing the text in a path alone may not address permissions or folder-selection differences.
Macro Security and Safe Use
Macros can change or delete workbook data and may perform other actions allowed by the code. Only enable macros in files from a source you trust, and be cautious with unexpected attachments or downloads. If a file arrives with a request to enable content, verify why the macro is needed with the sender rather than treating the prompt as routine.
Excel’s macro-security options are available through its security or macro settings; the precise labels and available choices can vary by Excel release. Avoid setting Excel to enable all macros by default. If you are unsure what a macro does, inspect its code in the Visual Basic Editor, test it on a duplicate workbook, and check for file access, external links, or calls to other applications.
Keep a clean backup before running code that edits many cells. VBA procedures do not provide the normal worksheet undo history, so Ctrl+Z on Windows or Command+Z on Mac will not reliably reverse a macro. For important workbooks, consider testing on a small sample and saving a separate output file.
Common Problems on a Mac
- The Developer tab is missing: Enable it in Excel’s Ribbon & Toolbar settings, then return to the workbook. The setting applies to the Excel interface, not just one worksheet.
- The macro is not listed: Confirm that the code is a public procedure in a standard module, that the correct workbook is open, and that the file is saved as .xlsm. A procedure requiring arguments will not normally appear as a simple runnable item in the Macros dialog.
- The code works on Windows but stops on Mac: Look for COM objects, ActiveX controls, Windows API declarations, hard-coded paths, or assumptions about folder permissions. The line that fails often points to the platform-specific dependency.
- The file opened but the macro did not run: Opening a workbook and permitting its macros are separate matters. Review Excel’s security prompt and settings, and do not lower security for a file whose source you cannot verify.
- A keyboard shortcut does nothing: Mac function keys may control brightness or media features by default. Try Fn with the shortcut, or use the Developer tab’s menu commands instead.
When to Use VBA, and Alternatives
VBA is useful when a task involves workbook-specific automation, repeated formatting, custom procedures, or older Excel tools built around macros. It is also practical when you need to maintain an existing .xlsm file. It may be a poor fit when every user must run the workbook in a browser, when the process depends on Windows-only integrations, or when macros are blocked by an organization’s security policy.
For simpler tasks, built-in Excel features may be easier to maintain: formulas can calculate results, tables can expand with new data, and Power Query can import and transform data where the required features are available in your Excel version. AppleScript can automate some Mac applications, but it is a separate technology rather than a replacement for VBA code inside a workbook. Choose based on where the file will run, who must support it, and whether the task needs to control Excel or other software.
Frequently Asked Questions
Can Excel for Mac run VBA macros?
Yes. The Excel desktop app for Mac can create, edit, and run VBA macros, although some Windows-specific code and controls are incompatible.
Can I use VBA in Excel for the web on a Mac?
No. Excel for the web does not run, create, or edit VBA. Open the workbook in the Excel desktop app to work with its macros.
How do I open the VBA editor on a Mac?
Enable the Developer tab in Excel’s Ribbon & Toolbar settings, then choose Developer > Visual Basic. Option+F11 is a shortcut; some keyboards require Fn as well.
Why does my Excel macro work on Windows but not Mac?
It may rely on COM automation, ActiveX, Windows API calls, or Windows file paths and permissions. Review the failing code and replace or separate the platform-specific part.
What file format keeps VBA macros?
Save a macro-enabled workbook as .xlsm. Saving as .xlsx removes the VBA project, so keep a backup and confirm the format before saving.
Related
- Data Validation Checklist for Excel: What to Check
- Conditional Formatting in Microsoft Project: What Works
- Data Validation and Verification in Excel Explained
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Protect a Sheet and Manage Permissions SafelyYes. In Excel VBA, protect a worksheet with its Protect method, for example Worksheets("Entry").Protect Password:="demo-pass". Add options such…
- Excel VBA InputBox Dropdown List: What Works InsteadNo: Excel VBA’s standard InputBox cannot display a dropdown list of choices. To offer a real dropdown, use…
- VBA Macros in Google Sheets: What Works InsteadNo. Google Sheets cannot run VBA macros: VBA is Microsoft Excel’s programming language, and Sheets uses Google Apps…
- Excel Worksheet Change Event: VBA Setup and ExamplesExcel’s Worksheet_Change event is a VBA procedure that runs when cells on a particular worksheet are changed, such…
- Excel VBA: Find a Match and Return Its Row NumberIn Excel VBA, use the column’s Range.Find method to locate a value, then read the found cell’s .Row…
- Excel Goal Seek VBA Code for a Whole ColumnTo run Goal Seek down a column, loop through the populated rows and call Range.GoalSeek once per row:…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.