Fix Excel Macro Returning Different OneDrive or SharePoint File Lists
Question details
Users are experiencing an issue where an Excel macro retrieves fewer or different files from a shared OneDrive or SharePoint directory depending on the user running it.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Running a VBA macro to retrieve a complete list of files from a shared SharePoint or OneDrive folder.
- Observed behavior
- The macro returns an incomplete list of files for specific users, even though they can view and edit all files properly when accessing the folder via the SharePoint web browser interface.
Ensure that the affected users are actively signed into their Microsoft accounts on their local OneDrive client. Verify that their local OneDrive sync is up to date, not paused, and actively syncing the specific SharePoint document library.
Verify Local OneDrive Sync Paths and Status
Ensure that the macro is pointing to the correct local synced path and that OneDrive has fully downloaded the files for the affected user.
VBA macros typically rely on local file paths rather than cloud URLs. If a user's local OneDrive is out of sync, or if files are marked as 'online-only' and the macro cannot trigger a download, the files will not appear in the macro's return list.
Open File Explorer and navigate to the user's local OneDrive or SharePoint synced folder where the target files reside.
Right-click the specific folder or files and select 'Always keep on this device' to force a complete download of all items to the local drive.
Click the OneDrive cloud icon in the Windows system tray to check for any sync errors, pending uploads, or paused syncing statuses.
Open the macro in the VBA editor (ALT + F11) and ensure the folder path relies on environmental variables (like Environ("USERPROFILE")) rather than hardcoded usernames.

Create a Test Folder to Isolate Permission Issues
Rule out hidden SharePoint permission conflicts by creating a fresh folder with explicitly mirrored access rights.
Check for Hidden Files and Macro Filtering
Ensure that the VBA macro isn't filtering out specific file types or ignoring hidden system files that one user might have configured differently in Windows.
Try WPS Office for Seamless Macro Execution and File Management
If Microsoft Excel permissions and OneDrive sync issues continue to disrupt your team's workflow, consider switching to WPS Office. It provides robust support for VBA macros, excellent compatibility with Microsoft formats, and a lightweight environment that minimizes complex syncing conflicts.
- 1. Download and install: Visit the official WPS website to download and install WPS Office on your computer.
- 2. Open Spreadsheets: Launch WPS Spreadsheets and open your existing .xlsm file containing the macros.
- 3. Enable macros: Navigate to the 'Developer' tab on the ribbon and click 'Macros' to securely run or edit your VBA scripts.

Frequently Asked Questions
Why does my Excel macro work perfectly for me but fail to list files for another user?
This usually happens due to hardcoded local file paths in the VBA code that differ by Windows username, mismatched SharePoint folder permissions, or incomplete OneDrive synchronization on the other user's computer.
Can reinstalling Microsoft Office fix macro file list issues?
Generally, no. Reinstalling Office does not resolve underlying SharePoint permission scopes, local OneDrive sync statuses, or logical path errors within the macro's VBA code.
How do I ensure my VBA macro uses the correct SharePoint path for all users?
Instead of hardcoding a direct path like C:\Users\JohnDoe\..., you should use VBA environmental variables such as Environ("USERPROFILE") & "\Company Name\SharePoint Folder" to dynamically adapt to each user's local synced path.
Why can a user see files in the SharePoint browser but not via the Excel macro?
The browser views the live files directly on the SharePoint server, while macros typically interact with the local synced copy via Windows File Explorer. If the local OneDrive app is paused, disconnected, or selectively syncing, the macro will not 'see' the latest cloud files.




