OneDrive File Issues

Fix VBA Dir and FileSystemObject with OneDrive Folders in Excel

Jason MillerJason Miller Nov 13, 2026 870 views

Question details

The user needs to use Excel VBA to open, process, and move files stored in OneDrive, but Dir and FileSystemObject fail when given an HTTPS OneDrive URL or cloud-style path.

Product
Microsoft Excel VBA and OneDrive
Device & OS
Windows
Scenario
An Excel VBA workflow must enumerate, open, process, and move OneDrive-stored workbooks by using Dir or FileSystemObject.
Observed behavior
Dir and GetFolder do not accept the OneDrive HTTPS URL or cloud-style path and return an error because they require a local or supported file-system path.
Before you start

Before editing VBA code, confirm that the OneDrive sync client is installed, you are signed in, and the target folder is set to sync locally to a Windows path. If the files must remain cloud-only, plan to use OneDrive API calls instead of file-system commands.

Solution 1Recommended

Sync the OneDrive folder and use its local Windows path in VBA

Use this when the target OneDrive folder can sync to the PC; VBA Dir and FileSystemObject can then process it like any local folder.

Dir and FileSystemObject do not accept HTTPS URLs. OneDrive sync provides a local folder, normally under C:\Users\<user>\OneDrive - <organization>\<folder>, that VBA can enumerate and manage.

1
Open OneDrive folder settings

Select the OneDrive cloud icon in the notification area, select Settings, then go to Account > Choose folders.

2
Choose the OneDrive folder to sync

In the Choose folders dialog, check the folder that contains the Excel files and click OK. Wait for OneDrive to finish syncing and show a green check.

3
Copy the local Windows path

Open File Explorer, navigate to the synced folder, click the address bar, and copy the path, for example C:\Users\yourname\OneDrive - Contoso\Reports.

4
Update VBA Dir or FileSystemObject code

Replace the OneDrive web URL with the copied path. For example, use Dir("C:\Users\yourname\OneDrive - Contoso\Reports\*.xlsx") or fso.GetFolder("C:\Users\yourname\OneDrive - Contoso\Reports") and run the macro again.

Synced files behave as local files: After the folder is synced, VBA can open, process, and move the files with standard local file commands.
Free Microsoft Office alternative

Use WPS Office to Work with OneDrive-Synced Excel Files

WPS Office is a free, lightweight Microsoft Office alternative that opens Excel workbooks and fits into OneDrive file workflows with a familiar ribbon UI, XLSX/XLSM format compatibility, and easy migration from Microsoft Office.

  1. 1. Download and install WPS Office: Download WPS Office from the official WPS website, run the installer, and sign in or skip to reach the main workspace.
  2. 2. Open a OneDrive-synced workbook: In WPS Spreadsheets, click Open, browse to the local OneDrive folder, and select the workbook to process.
  3. 3. Use built-in spreadsheet tools or compatible macros: Use WPS Spreadsheets tools for processing, or run supported macros on locally synced files instead of passing HTTPS URLs to file-system commands.
Opens OneDrive-synced Excel workbooks directly from their local Windows folder.Maintains compatibility with Microsoft Excel XLSX, XLSM, and CSV formats.Free, lightweight suite with a familiar user interface for easy migration.Lets you process and edit spreadsheet files without paying for Office productivity features.
microsoft office alternative - wps office

Frequently Asked Questions

Does VBA Dir support OneDrive HTTPS URLs?

No. VBA Dir and FileSystemObject only accept local, mapped, or UNC file-system paths. Sync the OneDrive folder and use its Windows path, or call Microsoft Graph APIs for cloud-only files.

How do I find the local path of a synced OneDrive folder?

Open File Explorer, browse to the OneDrive folder, and click the address bar to copy the full path. It is usually similar to C:\Users\<user>\OneDrive - <organization>\<folder>.

Can FileSystemObject move files inside a synced OneDrive folder?

Yes. Once the folder is available locally, FileSystemObject can copy, move, and delete files using the local Windows path just as it would for any other folder.

What should I do when OneDrive files are online-only and VBA cannot see them?

Use OneDrive Files On-Demand to download the folder locally before running the VBA macro, or use Microsoft Graph API to access cloud-only files directly.

Does WPS Office support VBA Dir on OneDrive folders?

WPS Office can open locally synced workbooks, but the VBA file-system limitation is the same: use a local sync path rather than an HTTPS OneDrive URL.