Yes. Microsoft Excel for Microsoft 365 on Windows can run VBA macros, provided they are allowed by your security settings and the workbook is saved in a macro-capable format such as .xlsm. Excel does not have one universal macro on/off switch: enabling the Developer tab exposes macro tools, while Trust Center settings control whether macros can run.
Does Excel support macros?
Excel’s traditional macros are small programs written in Visual Basic for Applications (VBA). They can automate repetitive work, such as formatting a report, copying data between sheets, or creating a standard monthly summary. A macro can also change or delete workbook content, so it is important to understand what it does before allowing it to run.
Excel for Windows and Excel for Mac can run VBA macros in desktop workbooks, though some features and integrations differ between the platforms. Excel for the web does not run VBA macros. Opening a macro-enabled workbook in a browser is not the same as running its code; use the desktop app when you need the VBA automation.
One common misunderstanding is that showing the Developer tab turns macros on. It does not. The tab provides commands for creating, viewing, and running macros, while Excel’s security rules separately determine whether code is permitted to execute.
What macro-enabled means for an Excel file
A macro-enabled workbook is a file format that can retain VBA code along with spreadsheet data. The most familiar format is .xlsm, formally called Excel Macro-Enabled Workbook. If a workbook contains macros, saving it as .xlsx will not preserve that VBA code: Excel warns that features may be lost, and the macros are removed if you continue in the non-macro format.
- .xlsm: The standard choice for a workbook that contains VBA macros.
- .xlsx: The usual workbook format, which cannot store VBA macros.
- .xlsb: A binary workbook format that can also contain VBA. It may be useful for some large or complex workbooks, but it is not required just because a file has macros.
- .xlam: An Excel add-in format used to distribute reusable tools and functions.
If Excel asks whether to keep the workbook in a macro-enabled format, choose .xlsm when you need its VBA code to remain available. If you do not need the macros, .xlsx is generally a better choice for an ordinary workbook. The file extension alone does not prove that code is safe: an .xlsm file may contain useful automation, unwanted code, or no macros at all.
Show the Developer tab and create a macro
In Excel for Microsoft 365 on Windows, enable the ribbon tab by selecting File > Options > Customize Ribbon, checking Developer in the Main Tabs list, and selecting OK. This only reveals the tools; it does not change macro security. On a Mac, open Excel > Settings (called Preferences in some versions) and choose Ribbon & Toolbar, then add or check Developer.
You can record a basic sequence without writing code: choose Developer > Record Macro, give the macro a name, choose where to store it, and perform the actions you want recorded. Select Developer > Stop Recording when finished. Recorded macros can include extra selections or navigation steps, so review the result before relying on it. A macro stored in the Personal Macro Workbook is intended to be available across workbooks on that computer; a macro stored in This Workbook stays with that workbook.
For example, the following short VBA procedure writes a marker into cell A1 on a sheet named Sheet1. It assumes that sheet exists. Save a copy of the workbook before running it: macro actions cannot be undone with Ctrl+Z, and a macro can change data.
Sub WriteMacroMarker()
Dim ws As Worksheet
' Write a simple marker to the named worksheet.
Set ws = ThisWorkbook.Worksheets("Sheet1")
ws.Range("A1").Value = "Macro ran"
End Sub
To inspect or edit VBA, use Developer > Visual Basic. To run a macro from the ribbon, choose Developer > Macros, select its name, and choose Run. On Windows, Alt+F11 opens the Visual Basic Editor and Alt+F8 opens the Macro dialog. On a Mac, Option+F11 or Fn+Option+F11 may open the editor depending on the keyboard’s function-key settings; menu commands are an alternative.
How Excel macro security works
Excel restricts macros because VBA code can do more than change a cell. Depending on the code and permissions, it may alter files, interact with other applications, or perform actions without the user’s normal step-by-step input. Treat an unexpected macro prompt as a security decision, not as a routine button to click through.
On Windows, inspect the controls under File > Options > Trust Center > Trust Center Settings > Macro Settings. The option commonly recommended for everyday use is Disable VBA macros with notification: Excel blocks macros by default but can show a warning for a file where a user can make a decision. Labels and available settings can vary by Office version or by an organization’s policy. Avoid Enable VBA macros for all files unless an administrator has a specific managed reason; it weakens an important protection. If the settings are unavailable or greyed out, an organization may control them.
When Excel shows a security warning for a workbook you trust, read the message and confirm the file’s source before choosing to enable its content. In some cases, files downloaded from the internet are blocked even if the general Trust Center setting permits notifications. Current Microsoft Office security behavior can block VBA from internet-marked files and display a message that macros are blocked because the source is untrusted.
Enable a trusted workbook safely
Use a cautious process rather than lowering security for every workbook:
- Check who sent the file and whether you expected it. If the message or attachment is unexpected, verify it with the sender through a separate channel.
- Confirm that the workbook’s purpose requires macros. Ask the sender what the macros do if that is not clear.
- Keep a clean copy before running code that edits important data. For valuable files, use a separate test copy first.
- If Excel blocks an internet-downloaded file, do not bypass the warning simply to make the prompt disappear. Follow your organization’s approved process or ask its IT team to verify the file.
For a file that you have independently verified, Windows may offer an Unblock checkbox in the file’s Properties dialog: close Excel, right-click the file in File Explorer, choose Properties, and look near the bottom of the General tab. This option is not present for every file or in every managed setup. Only use it for a file you trust. A Trusted Location can also make files in a designated folder trusted, but avoid adding broad folders such as Downloads; files placed there may receive fewer warnings.
Windows, Mac, and Excel for the web
Most basic VBA workbooks can be used in desktop Excel on Windows and Mac, but macros that depend on Windows-only components, particular file paths, or other applications may need changes to work on a Mac. A workbook might therefore open on both platforms while some of its automation works only on one. If a team uses different systems, test the specific macro on each supported platform and document any limitations.
Excel for the web does not execute VBA, even when the workbook is .xlsm. You can use the desktop app to run the macro. Office Scripts are a separate automation option associated with Microsoft 365; they are not VBA macros embedded in a workbook, and their availability depends on the account and environment. They may suit browser-based workflows, but they are not a drop-in replacement for every VBA project.
Common macro problems and fixes
- The Developer tab is missing: Customize the ribbon and check Developer. Remember, this makes the tools visible but does not authorize a macro to run.
- The macro is not listed: Confirm that the correct workbook is open, that it is saved in a format that retains VBA, and that the code is in a standard module or otherwise available to run. A macro saved only in another workbook will not necessarily appear in the current workbook’s list.
- Excel says the file type does not support macros: Save a copy as Excel Macro-Enabled Workbook (.xlsm) if the code needs to stay with the file. Do not simply change the extension by renaming the file.
- The file opens but the code does not run: Check the warning, macro settings, and whether the workbook came from the internet. A company policy may also prevent changes to macro settings.
- The macro works on Windows but not Mac: Review its dependencies. Platform-specific paths or components can break even when the VBA code itself is present.
Also distinguish a macro from a worksheet formula. A formula calculates a result in a cell; VBA is code that can automate a wider set of actions. If a task can be handled with built-in formulas, tables, or Power Query, those options may be easier to share and maintain than a custom macro.
Frequently Asked Questions
Is Excel macro enabled by default?
Excel supports macros, but it generally does not run every macro automatically. Security settings, file origin, and organization policies affect whether a particular VBA macro can run. A macro-enabled file extension does not mean the code is automatically trusted.
How do I enable macros in Excel?
For a trusted workbook, review Excel’s security warning and follow your organization’s approved process. On Windows, macro behavior is managed at File > Options > Trust Center > Trust Center Settings > Macro Settings. Do not turn on all macros just to run one file.
Can I run an .xlsm file in Excel Online?
Excel for the web can open macro-enabled workbooks, but it does not run VBA macros. Open the workbook in desktop Excel to use its VBA automation. A browser-based Office Script is a different feature.
Why did my macros disappear after saving?
The workbook may have been saved as .xlsx, which does not retain VBA code. Save a copy as .xlsm or another suitable macro-capable format before closing, and heed Excel’s warning about features that cannot be saved.
Is it safe to enable macros from an email attachment?
Not unless you have verified both the sender and the file’s purpose. Macros can make changes beyond ordinary cell calculations. If the attachment is unexpected, or Excel says the source is untrusted, do not enable its code without verification.
Related
- What Is Power Query? Excel Data Cleanup Explained
- AI and Power Query: What It Can and Cannot Do in Excel
- Power Query Split Cell Into Rows: Steps and Examples
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: How to Open a UserFormIn Excel VBA, open a UserForm by calling its Show method from a macro or another procedure. Use…
- Excel VBA Unprotect Sheet: Safe Methods and ExamplesTo unprotect a worksheet with VBA in Excel for Microsoft 365 on Windows, use Worksheet.Unprotect and supply the…
- Excel VBA: Count Visible Rows After AutoFilterTo count rows still visible after an AutoFilter, loop through the filter’s data rows and count those whose…
- VBA Range Column: How to Reference ColumnsIn VBA, reference a whole worksheet column with Columns("C") or Range("C:C"); to get the column containing a particular…
- Excel VBA Copy and Paste Range: Examples and TipsIn Excel VBA, copy a range to another location with sourceRange.Copy Destination:=destinationRange. For values only, assign the ranges…
- Excel Macro for Multiple-Selection Drop-Down ListsTo let a user choose several items from one Excel drop-down, add a VBA Worksheet_Change macro to the…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.