logo
search
VBA & Macro Problems

Fix Macro Errors When Running Excel Files from Synced SharePoint Folders

Algirdas JasaitisAlgirdas Jasaitis Oct 23, 2026 868 views

Question details

Users encounter a 'file not found in the same folder' error when trying to run macro-enabled Excel files from a locally synchronized SharePoint folder, even though the macros work perfectly when stored completely locally.

Fix Macro Errors When Running Excel Files from Synced SharePoint Folders
Product
Microsoft Excel
Device & OS
not provided
Scenario
Executing VBA macros from an Excel workbook (.xlsm) that is stored in a locally synced SharePoint or OneDrive folder via File Explorer.
Observed behavior
The macro execution fails and throws a file not found error. This typically happens because the VBA code expects a local file path, but the synchronized folder environment resolves dependent paths differently.
Before you start

Verify that all dependent workbooks are synchronized to the same local folder and that macros are enabled in your Excel Trust Center settings.

Solution 1Recommended

Create a User Environment Variable for the Excel Document

Setting up a dedicated environment variable can help the system correctly resolve the local path for the synced workbook.

This is a proven workaround for vendor-created workbooks where VBA code fails to resolve the correct local directory path in synchronized SharePoint or OneDrive environments. You will need to apply this variable for each user who accesses the file.

1
Open Environment Variables

Press the Windows key, type 'Environment Variables', and select 'Edit environment variables for your account' from the search results.

2
Create a New User Variable

In the Environment Variables window, click the 'New' button under the 'User variables' section.

3
Define the Variable Path

Enter a descriptive Variable name (e.g., 'SharePointSyncPath') and set the Variable value to the exact local folder path where your SharePoint files are synchronized. Click 'OK' to save.

4
Update VBA or System Configuration

Ensure your VBA code uses the Environ() function to retrieve this path, or configure the workbook to reference this environment variable instead of a hardcoded string.

Create a User Environment Variable for the Excel Document
Variable Scope: Since this is a User variable, it does not require administrative privileges to set up, but must be configured individually on each user's machine.
Free Microsoft Office alternative

Try WPS Office for Seamless Macro and VBA Support

If you continue to experience file path synchronization issues with Microsoft Excel and SharePoint, consider switching to WPS Office. It provides robust support for VBA and macro-enabled documents, offering a lightweight, familiar, and highly compatible alternative.

  1. 1. Download WPS Office: Visit the official WPS Office website and click the free download button.
  2. 2. Install the Software: Run the downloaded installer file and follow the on-screen instructions.
  3. 3. Open Your Macro-Enabled Files: Launch WPS Spreadsheets and open your .xlsm files to run your VBA macros seamlessly.
Free and lightweight office suite with a familiar user interfaceHigh format compatibility with Microsoft Excel (.xls, .xlsx, .xlsm)Built-in VBA editor for running, editing, and managing macros without complex sync errors
microsoft office alternative - wps office

Frequently Asked Questions

Why do my Excel macros work locally but not in a synchronized SharePoint folder?

When files are synced via OneDrive or SharePoint, Excel sometimes resolves the file path as a web URL (https://) instead of a local drive path (e.g., C:\). If your VBA code is designed to locate files in a local directory, it cannot read the cloud URL, triggering a 'file not found' error.

Can I run macro-enabled Excel files directly in the SharePoint web version?

No, macros are not supported in the web version of SharePoint or Excel Online. You must open the document in the desktop application to run or edit VBA code.

How can I prevent OneDrive from changing my local VBA paths to URLs?

You can turn off the 'Use Office applications to sync Office files that I open' setting in your OneDrive client, though this may affect real-time co-authoring. Alternatively, update your VBA code with a function that automatically translates the OneDrive URL back to the local path.