VBA & Macro Problems

Fix VBA Runtime Error 3004 When Writing a ZIP File in WPS Office

Algirdas JasaitisAlgirdas Jasaitis Nov 13, 2026 869 views

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.

Fix VBA Runtime Error 3004 When Writing a ZIP File in WPS Office
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 you start

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.

Solution 1Recommended

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.

1
Open the destination folder in File Explorer

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.

2
Close any existing ZIP or locked files

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.

3
Check the path and file name in the VBA code

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.

4
Confirm free disk space and rerun the macro

Open This PC, check that the destination drive has sufficient free space, then run the macro again.

Expected result: After write permission is restored, the target file is closed, and the path is valid, the macro should write the ZIP archive without Runtime Error 3004.

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. 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. 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. 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. 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.
Run and debug Excel-compatible VBA macros directly in WPS Spreadsheets.Open and save Microsoft Excel .xlsm and .xlsx macro-enabled workbooks.Use a lightweight free Office suite with a familiar VBA editor and macro workflow.Keep Microsoft Office macro compatibility without switching to a paid Office subscription.
microsoft office alternative - wps office

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.