Fix VBA Runtime Error 3004 When Writing a ZIP File in WPS Office
Question details
The user needs to resolve VBA Runtime Error 3004 when an Excel or WPS Spreadsheets macro writes a ZIP archive, including checking write permissions, file paths, locked archives, disk space, and security software.

- Product
- WPS Office Spreadsheets
- Device & OS
- not provided
- Scenario
- An Excel macro retrieves files from a folder and combines them into a ZIP archive.
- Observed behavior
- The macro fails with Runtime Error 3004: Failed to write to file.
Before running the macro again, note the exact destination folder used in the VBA code and make sure the target ZIP file is closed. Also confirm that your Windows user account can create and overwrite files in that folder.
Check destination permissions, path, and disk space before rerunning the macro
Use this first to rule out the most common write failures that cause Runtime Error 3004.
Most Runtime Error 3004 failures when writing a ZIP file are caused by a blocked or invalid save location rather than by the ZIP routine itself. Start with the output folder before changing the macro code.
Press Win + E, navigate to the folder used by the ZIP macro, right-click the folder, select Properties > Security, and confirm your user account has Write permission.
If the archive already exists, close it in File Explorer or any compression tool and make sure the target ZIP file is not open or selected before running the macro.
In WPS Spreadsheets, press Alt+F11 to open the VBA editor and verify the output path contains no invalid characters such as < > : " / \ | ? * and that the path is not too long.
Open This PC, check that the destination drive has sufficient free space, then run the macro again.
Debug the exact file-writing line and test another destination folder
Use this if the first checks do not resolve the error and you need to isolate the failing VBA statement or a security block.
Fix VBA Runtime Error 3004 and Write ZIP Files in WPS Spreadsheets
Use WPS Spreadsheets to open and debug the Excel-compatible VBA macro, correct the destination path and permission issues, and run the ZIP-writing macro successfully.
- 1. Open the VBA editor in WPS Spreadsheets: In WPS Spreadsheets, press Alt+F11 to open the Microsoft Visual Basic for Applications editor and open the module that contains the ZIP-writing macro.
- 2. Set a safe destination path: Update the macro output path to a short local folder such as C:\Users\Public\Documents\MacroTest, and make sure the folder exists before running the code.
- 3. Check the file-writing statement: Find the Open, Put, Close, Name, or FileCopy line that writes the ZIP file. Press F8 to step through the macro and verify that no invalid characters or locked files cause the write to fail.
- 4. Run the macro and verify the ZIP file: Run the macro from the WPS Spreadsheets Developer tab or press F5 in the VBA editor, then open the destination folder to confirm the ZIP archive was created.

Frequently Asked Questions
Why does VBA Runtime Error 3004 happen when my macro creates a ZIP file?
It happens when the macro cannot write to the destination path, usually because of missing write permissions, an invalid or too-long file path, an existing archive that is open or locked, low disk space, or security software blocking the write.
How do I check the exact line that raises Runtime Error 3004?
Press Alt+F11 in WPS Spreadsheets or Excel to open the VBA editor, select the macro, and press F8 to step through the code until the error appears on the file-writing line such as Open, Put, Close, Name, or FileCopy.
Can I fix the error by changing the output folder?
Yes. Change the destination to a short local path like C:\Users\Public\Documents\MacroTest, make sure your user account has Write permission, and ensure the target ZIP file is not already open before running the macro.
Does antivirus software cause Runtime Error 3004?
Yes. Antivirus or endpoint protection can silently block macros from creating or modifying ZIP files. Temporarily test with the folder or macro added to the allowed list in the security console.
Is Runtime Error 3004 specific to Excel, or can it happen in WPS Office?
The same file-writing error can occur in WPS Office when running VBA macros that write files. The same path, permission, disk space, and code checks apply.




