Fix Excel VBA Runtime Error 3004 in Shared OneDrive Folders
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.

- 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.
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.
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.
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.
Press 'Alt + F11' on your keyboard to open the Microsoft Visual Basic for Applications window.
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.
In the Project Explorer, expand 'VBAProject (PERSONAL.XLSB)', insert a new module (Insert > Module), and paste your macro code into this new module.
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.

Map OneDrive URL to Local Sync Path in VBA
Modify your VBA code to translate the OneDrive HTTPS URL into a local file system path before saving the CSV file.
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. Download and Install: Get the free version of WPS Office from the official website and install it on your device.
- 2. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks seamlessly.
- 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.

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.




