logo
search
VBA & Macro Problems

How to Open OneDrive Files in Excel Desktop App Using VBA

Maira MehtabMaira Mehtab Sep 28, 2026 870 views

Question details

The user wants to use an Excel VBA macro to open a OneDrive-hosted file directly within the desktop application rather than launching it in a web browser.

How to Open OneDrive Files in the Excel Desktop App With VBA
Product
Microsoft Excel
Device & OS
Windows
Scenario
Running a VBA macro to access and open another spreadsheet hosted on a OneDrive account.
Observed behavior
Using the ActiveWorkbook.FollowHyperlink method defaults to interpreting the OneDrive file as a URL, opening it in a web browser instead of the Excel desktop app.
Before you start

Ensure that the OneDrive desktop client is installed, running, and actively synchronizing the target files to your local hard drive.

Solution 1Recommended

Use the Workbooks.Open Method with a Local Sync Path

The most reliable way to force Excel to open the file in the desktop app is to bypass the OneDrive web URL entirely and point your VBA script to the local synchronized folder.

When you use a standard OneDrive sharing link, Excel assumes it is a web resource. By referencing the local path created by the OneDrive sync client, Excel treats it like a standard local file.

1
Locate the local path

Open File Explorer and navigate to your synced OneDrive folder. Find the target Excel file, right-click it, and select 'Copy as path'.

2
Open the VBA Editor

In Excel, press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

3
Insert the Workbooks.Open command

In your macro module, type the command: Workbooks.Open "C:\Users\YourName\OneDrive\Documents\Report.xlsx" (replacing the path with the one you copied).

4
Run your macro

Press F5 or run the macro from your workbook. The file will now open as a separate window in the Excel desktop application.

Dynamic Paths: If multiple users run this macro, consider using Environ("OneDrive") in your script to dynamically find the local path for different user profiles.
Advanced VBA Support in WPS Office

Execute Macros Seamlessly with WPS Office

WPS Office provides robust, built-in support for VBA and macros. You can run your existing Excel scripts, including local file operations and Workbooks.Open commands, directly in WPS Spreadsheet without rewriting your code.

  1. 1. Install WPS Office: Download and install WPS Office, ensuring you select the components that include VBA support.
  2. 2. Open WPS Spreadsheet: Launch WPS Spreadsheet and open your macro-enabled workbook.
  3. 3. Access the Developer Tools: Navigate to the Developer tab on the top ribbon and click on 'VBA Editor'.
  4. 4. Run your macro: Paste your Workbooks.Open code pointing to the local OneDrive folder and execute it perfectly within the WPS environment.
Highly compatible with Microsoft Excel VBA scripts and modulesFully supports .xls, .xlsx, and macro-enabled .xlsm file formatsHandles local file directories and Windows Shell commands effortlesslyLightweight, fast, and completely free to use for most tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why does ActiveWorkbook.FollowHyperlink open files in a web browser?

This method relies on Windows' default protocol handling for URLs. When provided with a OneDrive web link, the system sends the request to the default internet browser rather than passing it to the Excel desktop application.

How do I find my exact local OneDrive sync folder path?

Open File Explorer and navigate to your OneDrive folder on the left sidebar. Click in the address bar at the top of the window to reveal and copy the exact local directory path (e.g., C:\Users\Name\OneDrive).

Can I use VBA to open a OneDrive file if it isn't synced locally?

No, if you want to strictly use local file handling methods like Workbooks.Open with a 'C:\' drive path, the file must be synchronized locally. If it is entirely in the cloud, you are restricted to using web URLs.

How can I make my VBA code work for other users sharing the same OneDrive folder?

You can use the Environ command in VBA to dynamically fetch the user's root directory. For example, using Environ("USERPROFILE") & "\OneDrive\Documents\Report.xlsx" will automatically adapt the path for whoever runs the macro.