VBA & Macro Problems

Fix Excel VBA Cannot Use OneDrive or SharePoint HTTPS Paths

Elise WilliamsElise Williams Nov 2, 2026 871 views

Question details

User needs a way to make Excel VBA file functions work with files stored on OneDrive or SharePoint, as passing HTTPS paths directly causes errors.

How to Fix Excel VBA Errors with OneDrive and SharePoint HTTPS Paths
Product
Microsoft Excel
Device & OS
not provided
Scenario
Running VBA macros containing file-system functions like ChDir, Dir, or Open on files hosted on OneDrive or SharePoint.
Observed behavior
Legacy VBA file functions fail because ActiveWorkbook.Path returns an HTTPS URL instead of a local file path, which traditional VBA functions do not support natively.
Before you start

Ensure your OneDrive desktop sync client is installed, actively running, and signed into the same Microsoft account associated with your SharePoint or OneDrive files.

Solution 1Recommended

Use the OneDrive Sync Client to Map Local Paths

Sync your cloud files to your local drive so VBA can interact with standard Windows or macOS file paths instead of HTTPS URLs.

Traditional VBA file operations like Dir, ChDir, and Open require standard file system paths. Since ActiveWorkbook.Path returns a web URL for cloud files in modern Office versions, the most reliable approach is to sync the cloud directory locally and modify your VBA script to target the local path.

1
Sync the Cloud Library

Open OneDrive or SharePoint in your web browser, navigate to the document library you want to use, and click the 'Sync' button in the top menu to open the OneDrive desktop app.

2
Create Local Folder

Follow the prompts in the OneDrive app to create a local synced folder on your PC or Mac.

3
Update VBA Code

Modify your VBA code to reference the new local directory path (e.g., C:\Users\[Username]\OneDrive) instead of relying dynamically on the ActiveWorkbook.Path HTTPS URL.

Use the OneDrive Sync Client to Map Local Paths
Check Local Availability: Make sure the files are physically available on your local drive. You may need to right-click the synced folder and select 'Always keep on this device' so VBA scripts can read the files without delay.
Free Microsoft Office alternative

Upgrade Your Spreadsheet Experience with WPS Office

If you are struggling with Microsoft Excel's VBA limitations and complex cloud file synchronizations, consider trying WPS Office. It provides a highly compatible alternative with robust spreadsheet tools, built-in macro support, and straightforward local file management.

  1. 1. Download WPS Office: Visit the official WPS Office website and download the free installer package.
  2. 2. Install the Software: Run the setup file and follow the simple on-screen instructions to complete the installation.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheet and easily open your existing Excel workbooks to enjoy seamless compatibility and macro support.
Fully compatible with Microsoft Excel formats (.xls, .xlsx, .xlsm, .csv).Built-in support for VBA and modern JS macros for advanced automation without complex configuration.Lightweight installation and significantly faster loading speeds.Free to use with a familiar, user-friendly tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does ActiveWorkbook.Path return an HTTPS URL instead of a local path?

When an Excel file is opened directly from OneDrive or SharePoint with AutoSave enabled, Office treats it as a cloud file. Consequently, the Path property returns its web URL (HTTPS) rather than the local file path on your computer.

Which VBA file functions are affected by OneDrive HTTPS paths?

Legacy file system operations in VBA, including ChDir, Dir, Open, FileCopy, and Kill, are unable to read or process HTTPS web addresses and will return errors such as 'Bad file name or number' or 'Path not found'.

Can I force Excel VBA to convert the OneDrive HTTPS URL to a local path automatically?

There is no built-in native VBA function to toggle between the two path types automatically. However, you can write a custom VBA function that dynamically replaces the HTTPS prefix and domain with your local Windows environment variable (like Environ("USERPROFILE")) and corrects the forward slashes to backslashes.

Will my VBA macros work if someone else opens the shared OneDrive file?

If your macro uses a hardcoded local path (e.g., C:\Users\YourName\OneDrive), it will fail for other users. To fix this, construct the path dynamically using the Environ("USERPROFILE") function so it adjusts to the current user's local synced OneDrive folder automatically.