Yes, Excel VBA works with SharePoint, but with an important limitation: VBA code runs inside the Excel desktop application on your computer, not on the SharePoint server. So a macro-enabled workbook stored in SharePoint works fine as long as it is opened in desktop Excel — but the code will not run in Excel for the web, and opening files directly from a SharePoint library can cause problems unless the file is synced or downloaded first.

Why VBA Doesn't Run on the SharePoint Server

VBA is a programming language built into the desktop versions of Excel and other Office applications. When you click a button that runs a macro, the code executes on your local machine using the Excel installation there. SharePoint is a storage and collaboration platform — it stores the workbook file, manages permissions and versioning, and serves the file to users, but it has no VBA engine. Nothing you upload to SharePoint will "run" on the server by itself.

This is also why Excel for the web (which SharePoint uses when you open a file in the browser) cannot run VBA. Microsoft's browser-based Excel supports many formulas and formatting features, but macros are not supported there. If a workbook depends on macros, users need to open it in the desktop app.

The Macro-Enabled File Format Requirement

For VBA to survive at all in SharePoint, the workbook must be saved in a macro-enabled format:

  • .xlsm — the standard macro-enabled Excel workbook. This is what most people should use.
  • .xlsb — binary workbook format, also supports macros and often loads faster for large files.
  • .xltm — macro-enabled template, useful if users create new files from it.

A plain .xlsx file cannot contain VBA. If someone opens a macro-enabled workbook and saves it as .xlsx, the code is stripped out permanently. SharePoint itself can block certain file types by default — notably older .xls files in some configurations and add-in files like .xla and .xlam — so if an upload is refused, the file extension is the first thing to check with your SharePoint admin.

Opening Files from SharePoint: Sync vs. Browser vs. Download

How you get the file off SharePoint matters a lot for whether macros behave reliably:

  1. Sync with OneDrive. Click Sync on the SharePoint library, and the files appear in a local folder through the OneDrive sync client. Open the file from that folder and it behaves like any local file — this is the most reliable method for VBA-heavy workbooks.
  2. Open in the desktop app from the browser. In the SharePoint or Excel web view, choose Open in Desktop App (the exact wording can differ slightly by version). Excel opens the file from the server and macros generally run, though some operations that save or write to disk can behave unpredictably over the network.
  3. Download, then open. Download a copy and work on it locally. Macros run perfectly, but you must upload the file again afterward and risk version conflicts if others edit it.

Opening directly in Excel Online and expecting macros to work is the most common failure point — users see the workbook but their buttons and automation do nothing.

Common Problems with VBA Workbooks in SharePoint

  • Macros silently do nothing. Almost always because the file was opened in Excel for the web, or it was saved as .xlsx and the code was stripped.
  • Trust Center blocks macros. Desktop Excel may disable macros in files that came from the internet, and SharePoint URLs can trigger this. Users see a security warning above the formula bar. Adding the SharePoint or synced location as a Trusted Location in Excel's Trust Center resolves this — note that modern Excel versions may still block macros in files marked as coming from the internet unless the file is unblocked.
  • Broken file paths in code. VBA that hard-codes a local path (like C:\Reports\data.csv) breaks for other users. On a synced library, each user has a different local folder path, so it's better to build paths relative to the workbook's own location using ThisWorkbook.Path.
  • Check-out and versioning conflicts. If the library requires check-out, the code's save operations may fail with errors. Co-authoring, which SharePoint enables for workbooks, is not compatible with macros running while multiple people edit — for macro-driven files it's usually better to require check-out.
  • SharePoint blocking uploads. Administrators can restrict file types; .xlsm is normally allowed but verify with IT if uploads fail.

What VBA Can Do With SharePoint Deliberately

Besides just being stored there, VBA can actively interact with SharePoint from the desktop:

  • Open or save files to SharePoint URLs directly using Workbooks.Open with the https address of the library, provided the user has permission and has authenticated.
  • Call SharePoint's REST API from VBA (using MSXML2.XMLHTTP or similar) to read or write list data without opening a browser.
  • Automate publishing a workbook to a document library as part of a reporting routine.

These are legitimate, widely used techniques, but they require the code to run in desktop Excel and the user to have appropriate site permissions. Authentication in organizations with modern sign-in policies can complicate scripted access, so IT involvement is often needed.

Alternatives When VBA in SharePoint Isn't Enough

  • Office Scripts — Microsoft's supported scripting solution for Excel on the web and desktop. If your workflow must run in the browser, Office Scripts (TypeScript-based, run via the Automate tab in Excel for the web) are the official replacement path. They cannot run VBA, but many common tasks can be rewritten.
  • Power Automate — for workflows triggered by file changes in SharePoint, such as approvals, notifications, or moving data, without any code in the workbook.
  • Power Query and Power BI — if the VBA's job is mainly pulling and reshaping SharePoint list or file data for reporting, these tools often do it more robustly.
  • Add-ins built with Office JavaScript API — for organizations that need custom functionality working in both desktop and web Excel.

Best Practices for Running Macro Workbooks From SharePoint

  1. Save as .xlsm and never let users re-save as .xlsx.
  2. Have users sync the library via OneDrive or open in the desktop app — never rely on Excel for the web.
  3. Use ThisWorkbook.Path for any related files instead of hard-coded paths.
  4. Require check-out on the library if macros modify and save the file.
  5. Have IT confirm .xlsm uploads are allowed and consider adding the site as a Trusted Location via policy.
  6. Sign your macros or distribute them through trusted channels so security warnings don't train users to click through warnings blindly.

Frequently Asked Questions

Do macros work in Excel Online?

No. Excel for the web does not support VBA macros at all. A macro-enabled workbook will open and display its data, but no code will run. You must open the file in desktop Excel to execute macros.

Why are my macros disabled when I open a file from SharePoint?

Excel's security settings block macros in files treated as coming from an internet location. Enable the content via the security warning, ask your admin to add the SharePoint location as a Trusted Location, or open the file from a synced OneDrive folder. Only enable macros in files from sources you trust.

Can I write VBA code that uploads files to SharePoint?

Yes. Desktop Excel can save directly to a SharePoint document library URL, and VBA can call SharePoint's REST API for list and library operations. It requires desktop Excel, valid permissions, and possibly IT help with authentication in secured environments.

Can multiple people run a macro workbook at the same time on SharePoint?

Not reliably. Co-authoring and macros don't mix well — if two people open and run code that changes and saves the file, changes can conflict. Libraries with macro workbooks are usually set to require check-out so only one person edits at a time.

Is there a way to run VBA automatically on a schedule with SharePoint?

Not on SharePoint itself. Options include a scheduled task on a machine running desktop Excel, or replacing the VBA with Power Automate or Office Scripts, which can run on a schedule in the Microsoft cloud.

Will converting my .xlsm to .xlsx keep the macros?

No. Saving as .xlsx permanently removes all VBA code from the workbook. Always keep a backup of the macro-enabled version before any format conversion.