Fix Excel VBA Cannot Use OneDrive or SharePoint HTTPS Paths
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.

- 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.
Ensure your OneDrive desktop sync client is installed, actively running, and signed into the same Microsoft account associated with your SharePoint or OneDrive files.
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.
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.
Follow the prompts in the OneDrive app to create a local synced folder on your PC or Mac.
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.

Utilize Microsoft Graph API or Office Scripts
If you cannot sync files locally, transition to modern web APIs designed specifically for cloud operations.
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. Download WPS Office: Visit the official WPS Office website and download the free installer package.
- 2. Install the Software: Run the setup file and follow the simple on-screen instructions to complete the installation.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheet and easily open your existing Excel workbooks to enjoy seamless compatibility and macro support.

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.




