How to Open OneDrive Files in Excel Desktop App Using VBA
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.

- 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.
Ensure that the OneDrive desktop client is installed, running, and actively synchronizing the target files to your local hard drive.
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.
Open File Explorer and navigate to your synced OneDrive folder. Find the target Excel file, right-click it, and select 'Copy as path'.
In Excel, press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
In your macro module, type the command: Workbooks.Open "C:\Users\YourName\OneDrive\Documents\Report.xlsx" (replacing the path with the one you copied).
Press F5 or run the macro from your workbook. The file will now open as a separate window in the Excel desktop application.
Execute via the Windows Shell
You can use the Windows Shell object within VBA to trigger the system's default behavior for opening files, guaranteeing it launches the desktop app.
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. Install WPS Office: Download and install WPS Office, ensuring you select the components that include VBA support.
- 2. Open WPS Spreadsheet: Launch WPS Spreadsheet and open your macro-enabled workbook.
- 3. Access the Developer Tools: Navigate to the Developer tab on the top ribbon and click on 'VBA Editor'.
- 4. Run your macro: Paste your Workbooks.Open code pointing to the local OneDrive folder and execute it perfectly within the WPS environment.

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.




