logo
search
VBA & Macro Problems

How to Fix Excel VBA Cannot Open File Stored in OneDrive

Maira MehtabMaira Mehtab Sep 21, 2026 870 views

Question details

The user needs to fix a VBA macro that fails to open an Excel workbook hosted on OneDrive via an HTTPS URL.

Product
Microsoft Excel
Device & OS
not provided
Scenario
Running a recorded VBA macro that uses the Workbooks.Open method with a OneDrive cloud URL (https://d.docs.live.net).
Observed behavior
The file initially opens in Microsoft Edge, but the macro fails or crashes when attempting to open the file again after the workbook has been closed.
Before you start

Ensure that the OneDrive desktop client is installed and actively syncing your cloud files to your local hard drive.

Solution 1Recommended

Use the Synchronized Local File Path in VBA

Update your VBA code to reference the local OneDrive folder path instead of the cloud URL, as the Workbooks.Open method is designed for local drives.

When recording macros in Excel, the recorder often captures the cloud URL (https://d.docs.live.net) for files saved in OneDrive. However, using cloud URLs with the Workbooks.Open method can cause the system to route the request to a web browser or fail entirely when executed repeatedly.

1
Locate the Synchronized File

Open Windows File Explorer and navigate to your local OneDrive folder where the target Excel workbook is stored.

2
Copy the Local Path

Hold down the Shift key on your keyboard, right-click the Excel workbook, and select 'Copy as path' from the context menu to copy the local C: drive directory.

3
Update the VBA Macro

Open the Excel VBA Editor (Alt + F11), locate the module containing your recorded macro, and replace the HTTPS cloud URL in the Workbooks.Open statement with the local path you just copied.

Dynamic File Paths for Multiple Users: If you plan to share this macro with other users, local paths containing specific usernames will fail. Use the VBA Environ("UserProfile") function to dynamically build the local OneDrive path based on the active Windows account.
Free Microsoft Office alternative

Run Macros Smoothly with WPS Office

If you are tired of complex cloud path issues and macro errors in Microsoft Excel, consider switching to WPS Office. It provides robust, reliable support for VBA and macros without the URL resolution conflicts.

  1. 1. Download and Install WPS Office: Download the free WPS Office suite from the official website and install it on your computer.
  2. 2. Enable Macro Features: Open WPS Spreadsheet, navigate to the Developer tab, and ensure that VBA macros are enabled for your workspace.
  3. 3. Open Your XLSM Files: Directly open your existing macro-enabled Excel workbooks in WPS Office to continue your automated workflows without compatibility issues.
Fully compatible with Microsoft Excel (.xlsx, .xlsm, .xls) macro-enabled formats.Built-in robust VBA editor to create, edit, and run macros seamlessly.Lightweight installation with an intuitive, tabbed user interface.Free to download and use for your daily spreadsheet and automation tasks.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Workbooks.Open launch Microsoft Edge instead of opening the file in Excel?

When a VBA macro uses an HTTPS cloud URL (like d.docs.live.net), Windows may interpret the link as a web address rather than a local file, prompting the system's default web browser to handle the request.

How do I find the local path of my OneDrive file for my VBA code?

Open File Explorer, navigate to your synced OneDrive folder, locate your Excel file, hold the Shift key while right-clicking the file, and select 'Copy as path'. You can paste this directly into your VBA script.

Will fixing the path to a local drive prevent the file from syncing to OneDrive?

No. As long as the file is located within your designated local OneDrive folder, the OneDrive desktop client will continue to automatically sync any changes you make via the macro to the cloud.