Excel VBA Online: Run Macros Without Desktop Excel
In this article
You cannot run VBA macros in Excel for the web. The browser version of Excel has no VBA editor and cannot execute .xlsm macro workbooks, so any automation written in VBA needs the desktop Excel application on Windows or Mac. What you can do online is write, review and store VBA code in a shared file and run it later on a full desktop install, and you can automate the same spreadsheet tasks in the browser with Office Scripts and Power Automate instead. This guide explains what works where, how to prepare a macro workbook so it survives a trip through the cloud, and the practical routes for getting VBA to run when you only have a browser.
What You'll Need
- A Microsoft 365 account with access to Excel for the web, and the desktop Excel app installed on at least one machine if you actually need to execute VBA.
- A macro-enabled workbook saved as
.xlsm(not.xlsx). The format is what tells Excel the file may contain code. - Permission to enable macros on the desktop machine. Many company networks block macros by policy, so check with whoever administers your Microsoft 365 tenant before building anything important.
- For the browser-only route, an Office Scripts-capable Microsoft 365 plan or a Power Automate licence, since these are the supported automation tools in the web app.
- A OneDrive or SharePoint location for the file if you want colleagues to open it from a link.
Step-by-Step
- Decide what "online" needs to mean for you. If the goal is simply to open a macro workbook from a browser link and read or edit the data, the web app handles that fine, it just will not run the code. If the goal is to have a button do something automatically, you need desktop Excel or an Office Scripts rewrite. Being clear about this first saves hours of fighting the browser.
- Upload the macro workbook to OneDrive or SharePoint. Sign in at office.com, open OneDrive, and use the Upload button to add your
.xlsmfile. Keep it in a folder you control rather than a shared folder with edit rights for everyone, at least while you are testing. - Open it in Excel for the web and confirm what you see. Click the file. The workbook opens in the browser. A banner typically appears explaining that macros will not run in the browser, and anything the macros were supposed to calculate stays at its last saved values. Menu labels and banner wording shift slightly between versions and regions, so read the message rather than looking for an exact phrase.
- Treat the browser session as read-and-edit only. You can type into cells, add formulas, format ranges, insert sheets and share the file. What you cannot do is press a macro button, open the VBA editor, or record a macro. If the workbook contains buttons, they appear as shapes and do nothing when clicked.
- Save in the same
.xlsmformat. When you edit and close, make sure the file is not quietly converted to.xlsx. Converting to the standard format strips the code permanently, and there is no undo. If the web app warns that some features may be lost, cancel and reconsider rather than accepting. - To run the code, open the file in desktop Excel. Use the Open in Desktop App button in the ribbon, or open the synced OneDrive folder in File Explorer or Finder and double-click the file. Desktop Excel shows a security bar asking whether to enable content. Enable it only if you trust the source of the file, and only on a machine where macros are permitted.
- If macros are blocked even on desktop, check the trust settings. In desktop Excel, open File and then Options, go to the Trust Center, and open Trust Center Settings. Look at the Macro Settings section. In managed environments these options are often locked by policy and greyed out, which means your administrator has decided for you. Do not attempt to loosen security settings on a work computer without permission.
- For a genuinely browser-based automation, build an Office Script instead. In Excel for the web, open the Automate tab and choose to create a new script. Scripts are written in TypeScript, not VBA, and they record and replay actions inside the web workbook. This is the supported path for automation that must run without the desktop app.
- Use Power Automate for scheduled or trigger-based runs. The Automate tab also lets you send a script to Power Automate, where it can run on a schedule or when a file changes. This is how you get a spreadsheet task to happen without anyone opening the workbook at all.
- Test on a copy before trusting it. Duplicate the workbook, run the desktop macro or the script on the duplicate, and compare the results with what you expect. Keep the original untouched until the automation has proven itself on real data.
Common Mistakes
Expecting the browser to run the macro. The most common frustration is opening a working macro workbook online, clicking the button, and concluding the file is broken. It is not broken; the browser simply has no VBA engine.
Saving as .xlsx. A well-meaning "save a copy" in the web app can produce a macro-free file. Once saved in that format, the code is gone. Always confirm the extension after any save from the browser.
Opening untrusted macro files. A macro can do almost anything on your machine, including reaching other files. Never enable content on a workbook that arrived by email from someone you do not know, however plausible the filename.
Assuming Office Scripts are a drop-in replacement. They are not. Scripts use a different language, a different object model and different limits. Anything relying on Windows APIs, external program calls or user forms will need rethinking, not translating.
Sharing a macro workbook with people who only have the browser. Colleagues on the web version will see stale values and dead buttons. Tell them plainly, or convert the task to a script that they genuinely can run.
Tips
Keep a version of the workbook that is purely data, with no code, for people who only need to look at numbers in the browser. That file opens faster and never triggers a macro warning.
Store the VBA source somewhere readable as plain text as well, such as a comment block or a separate notes file, so you can see what a workbook does without opening the editor.
When migrating a macro to a script, jot down what the macro does in plain sentences first: which sheet, which range, what calculation, what gets written where. The rewrite goes far faster from a written spec than from clicking through the original code.
Name your sheets and use Excel Tables rather than fixed ranges. Scripts and macros both cope better with tables that grow, and you avoid editing hard-coded cell references later.
If several people need to run the same automation, prefer a script with a button in the Automate tab over emailing a macro workbook around. It avoids the repeated security prompts and keeps one version in one place.
Troubleshooting
The file opens online but nothing happens when I click a button. That is expected behaviour. Open it in desktop Excel instead.
The workbook no longer has its code after editing online. Check the file extension. If it is now .xlsx, the code was removed on save. Restore an earlier version from the file's version history in OneDrive, which keeps prior copies for a period.
Desktop Excel shows a security warning on every open. The file is in a location Excel treats as untrusted. Moving it into a trusted folder or asking your administrator about trusted locations usually settles it. Do not disable macro security wholesale.
Macros are greyed out or blocked with a policy message. Group policy is controlling the setting. Only your administrator can change it; there is no safe workaround.
The Automate tab is missing. Office Scripts availability depends on your Microsoft 365 plan and on whether your organisation has enabled it. If it is not there, check with your administrator or confirm your plan includes it.
A script fails on a large file. Scripts have runtime and size limits. Splitting the work into smaller steps, or moving the heavy lifting to Power Automate with several script calls, often gets it through.
Frequently Asked Questions
Can I use the VBA editor in Excel for the web?
No. The browser app has no VBA editor and no way to run VBA. You need desktop Excel on Windows or Mac to write or execute macros.
Will a macro workbook still work if I edit it online?
It will open and you can change data, but the macros will not run in the browser. As long as the file stays in the .xlsm format, the code remains intact and runs the next time you open it on the desktop.
What is the online equivalent of a macro?
Office Scripts, built from the Automate tab, and Power Automate flows that call them. Both are written in TypeScript and run through Microsoft's own service, not through VBA.
Can I convert a VBA macro into an Office Script automatically?
Not reliably. There is no supported converter that preserves behaviour. The practical approach is to rewrite the logic step by step, using the original macro as a specification.
Do macros run when a workbook is opened in Teams or SharePoint preview?
No. Previews in Teams, SharePoint and other viewers display the saved values only. Anything that requires code to run needs the desktop app.
Is it safe to enable macros in a file from a colleague?
Only if you are confident about where the file came from and what it does. Macros can modify files and run commands on your computer. When in doubt, ask the sender to explain the code or to send a macro-free copy.