Fix Excel VBA Run-time Error 1004: SaveAs to OneDrive and SharePoint
Question details
The user needs to prevent Run-time error 1004 in Excel VBA when saving workbooks to OneDrive or SharePoint folders.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Executing a VBA macro using ActiveWorkbook.Save or SaveAs to write a file to a cloud-synchronized folder.
- Observed behavior
- The macro triggers Run-time error 1004. This typically happens when the destination folder is not fully synchronized locally, or the OneDrive client is closed.
Ensure your computer has an active internet connection and that the target SharePoint library is fully synchronized to your local machine.
Verify Local Synchronization and Use Dynamic Paths
Ensure the OneDrive client is actively running and properly synced to avoid path resolution failures during the SaveAs operation.
Run-time error 1004 frequently occurs when a VBA macro attempts to save to a cloud path that is currently inaccessible. Verifying synchronization and dynamically pointing to the user's local OneDrive folder resolves this issue.
Before running the SaveAs command, verify that the OneDrive cloud icon appears in your system tray, indicating the sync client is active.
If the OneDrive client might be closed, use a Shell command in your macro to open it before saving: Shell "explorer.exe 'C:\Program Files\Microsoft OneDrive\OneDrive.exe'", vbNormalFocus
For shared reports, construct dynamic VBA paths using Environ("UserProfile") so the macro automatically adapts to each user's local synchronized SharePoint folder.
Terminate and Restart OneDrive with VBA
If OneDrive is unresponsive or stuck, you can force it to close and restart using VBA shell commands before attempting to save.
Experience Stable Macro Execution with WPS Office
If Microsoft Excel's cloud synchronization mechanics are causing frequent VBA interruptions and SaveAs errors, consider trying WPS Office. It provides a lightweight, highly compatible alternative for your spreadsheet and macro needs.
- 1. Download WPS Office: Visit the official website to download the free installer.
- 2. Install the Application: Follow the on-screen instructions to install WPS Office on your device.
- 3. Open Your Workbooks: Launch WPS Spreadsheets and seamlessly open your existing macro-enabled files.

Frequently Asked Questions
Why does my VBA script throw Run-time error 1004 when saving to SharePoint?
This error generally occurs because the target SharePoint folder is not synchronized locally, or the OneDrive client is not currently running, making the destination path inaccessible to the macro.
Can I force SharePoint to synchronize using VBA?
No, VBA cannot directly force SharePoint to sync files. You can only ensure that the OneDrive client is running and rely on its native background synchronization process.
What causes Run-time error 53 when trying to restart OneDrive?
Run-time error 53 indicates that the specified executable file cannot be found. This typically happens if your VBA Shell command uses an incorrect file path or improper quotation formatting when attempting to restart OneDrive.exe.




