logo
search
VBA & Macro Problems

Fix Excel VBA Run-time Error 1004: SaveAs to OneDrive and SharePoint

Guest WriterGuest Writer Oct 9, 2026 869 views

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.
Before you start

Ensure your computer has an active internet connection and that the target SharePoint library is fully synchronized to your local machine.

Solution 1Recommended

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.

1
Confirm OneDrive is running

Before running the SaveAs command, verify that the OneDrive cloud icon appears in your system tray, indicating the sync client is active.

2
Start OneDrive via VBA

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

3
Implement dynamic paths

For shared reports, construct dynamic VBA paths using Environ("UserProfile") so the macro automatically adapts to each user's local synchronized SharePoint folder.

SharePoint Requirement: Every user running the macro must have appropriate access to the SharePoint library and must have it synchronized locally for the dynamic path to work.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official website to download the free installer.
  2. 2. Install the Application: Follow the on-screen instructions to install WPS Office on your device.
  3. 3. Open Your Workbooks: Launch WPS Spreadsheets and seamlessly open your existing macro-enabled files.
Fully compatible with Microsoft Office formats (.xlsx, .xlsm, .csv)Built-in VBA support to run your existing macros seamlesslyLightweight application that requires fewer system resourcesFree to download with an intuitive and familiar user interface
microsoft office alternative - wps office

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.