VBA & Macro Problems

Fix Excel VBA Runtime Error 3004 in Shared OneDrive Folders

Ayan MasoodAyan Masood Nov 3, 2026 870 views

Question details

The user needs a way to bypass an error when running a VBA macro to save CSV files from a shared OneDrive environment.

Fix Excel VBA Runtime Error 3004 in Shared OneDrive Folders
Product
Excel
Device & OS
not provided
Scenario
Running an Excel VBA macro to save a CSV file from a workbook that is stored in a shared OneDrive for Business directory.
Observed behavior
The macro throws a Runtime Error 3004 in the shared OneDrive for Business folder, despite working perfectly when the workbook is stored in a local folder or a personal OneDrive account.
Before you start

Verify that your OneDrive for Business client is actively syncing to your local machine and that you have full write permissions for the shared folder.

Solution 1Recommended

Move Macro Code to the Personal Macro Workbook (Personal.xlsb)

Transferring your VBA code to the local Personal.xlsb file separates the macro execution from the cloud-synced workbook, bypassing the path conflicts that trigger Error 3004.

By default, VBA macros embedded in a workbook stored on OneDrive for Business attempt to execute using the cloud's HTTPS path. Standard VBA file-saving commands often fail to process these SharePoint/OneDrive web paths, causing Error 3004. Moving the macro to your local Personal Macro Workbook forces the script to run locally.

1
Generate Personal.xlsb

If you don't already have a Personal Macro Workbook, go to the 'View' tab, click 'Macros', select 'Record Macro', choose 'Personal Macro Workbook' from the drop-down, and stop recording.

2
Open the VBA Editor

Press 'Alt + F11' on your keyboard to open the Microsoft Visual Basic for Applications window.

3
Copy the macro code

In the Project Explorer pane on the left, locate the shared OneDrive workbook, open its modules, and copy the VBA code that is causing the error.

4
Paste into Personal.xlsb

In the Project Explorer, expand 'VBAProject (PERSONAL.XLSB)', insert a new module (Insert > Module), and paste your macro code into this new module.

5
Run the macro locally

Save your changes and close the VBA editor. You can now run the macro directly from your Personal workbook while working inside the shared OneDrive files.

Move Macro Code to the Personal Macro Workbook (Personal.xlsb)
Workaround Confirmed: Running the macro from Personal.xlsb successfully routes the script execution locally, preventing OneDrive sync protocols from disrupting the file-saving process.
Free Microsoft Office alternative

Use WPS Office for Reliable Spreadsheet Management

If complex VBA and OneDrive path errors are disrupting your workflow, WPS Office offers a stable, lightweight, and highly compatible alternative for handling spreadsheets. It simplifies local and cloud file saving without triggering tedious network protocol errors.

  1. 1. Download and Install: Get the free version of WPS Office from the official website and install it on your device.
  2. 2. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks seamlessly.
  3. 3. Manage Data Easily: Edit your data and export or save CSV files directly to any local or synced folder without experiencing web path errors.
Excellent format compatibility with Microsoft Excel files (.xlsx, .xls, .csv).Reliable local file saving processes free from forced cloud-path conflicts.Lightweight software suite with a clean, familiar tabbed interface.Free to use for daily spreadsheet editing and data management.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get Runtime Error 3004 when saving files to OneDrive for Business via VBA?

This error happens because OneDrive for Business returns a web-based HTTPS URL for shared workbooks instead of a local file path. Standard VBA commands designed to write local files (like saving a CSV) cannot resolve these web URLs natively.

What is the Personal.xlsb file and where is it located?

Personal.xlsb is a hidden macro workbook in Excel that loads automatically in the background. It is typically stored in the XLSTART folder on your local C: drive, allowing any macros saved there to run locally across all your open Excel files.

Does WPS Office support VBA macros?

Yes, WPS Office supports VBA macros in its Professional and Business editions, offering a familiar editor interface and excellent compatibility with scripts originally written in Microsoft Excel.