Excel Error Codes

Fix Excel VBA SaveAs Error 1004 Using Full File Paths

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 870 views

Question details

The user encounters a runtime Error 1004 during a VBA SaveAs operation while converting XLSM workbooks to XLSX format. The macro incorrectly references an unrelated System32 directory path.

Fix Excel VBA SaveAs Error 1004 Using Full File Paths
Product
Microsoft Excel
Device & OS
not provided
Scenario
Executing a VBA macro loop to batch convert and save multiple XLSM files as standard XLSX workbooks.
Observed behavior
The SaveAs method fails with runtime Error 1004 and attempts to save to the System32 folder instead of the intended target directory. Hardcoding the explicit path temporarily bypasses the error.
Before you start

Before modifying your VBA script, ensure you have read and write permissions for the target folder and close any open instances of the files you intend to process.

Solution 1Recommended

Use Explicit Full File Paths with ThisWorkbook.Path

Resolves path resolution failures by dynamically building explicit source and destination file paths instead of relying on the active or current directory.

When a VBA macro executes without explicitly defined directory paths, the application may default to the system's current working directory, which can sometimes incorrectly resolve to the Windows System32 folder. Dynamically building the full path ensures the SaveAs method accurately targets the correct folder.

1
Declare full path variables

In your VBA editor (ALT + F11), declare string variables for both the source directory and the destination filename.

2
Define the source directory

Assign the directory of the current macro workbook to your variable using 'SourcePath = ThisWorkbook.Path & "\"' to guarantee correct folder targeting.

3
Construct the complete destination path

Concatenate the destination folder path with the desired filename and the new '.xlsx' extension to form a complete absolute path.

4
Update the SaveAs method

Modify your SaveAs command to use the complete path variable and explicitly state the format type: 'ActiveWorkbook.SaveAs Filename:=DestinationPath, FileFormat:=xlOpenXMLWorkbook'.

Avoid Endless File Loops: When looping through a folder to convert files, ensure your macro filters strictly for '.xlsm' extensions to prevent it from reopening and attempting to process the newly generated '.xlsx' files.
Free Microsoft Office alternative

Run Your Spreadsheets Smoothly with WPS Office

If you are consistently dealing with complex runtime errors or macro configuration issues, consider switching to WPS Office. It provides a lightweight, highly compatible environment for your spreadsheets with excellent support for legacy and modern formats.

Fully compatible with Microsoft Excel (.xlsx, .xlsm, .csv) formats.Advanced spreadsheet functionalities with a familiar, intuitive user interface.Lightweight installation that minimizes system resource usage.Completely free to use for your core data analysis and formatting needs.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel VBA Error 1004 reference the System32 folder?

When a VBA script uses a relative path or fails to specify a complete file path during a SaveAs operation, the application defaults to the current working directory. In certain environment setups, automated executions, or background processes, this working directory defaults to Windows\System32, causing the operation to fail due to lack of write permissions.

How do I correctly specify the XLSX format in a VBA SaveAs macro?

To properly save a workbook as an XLSX file, you must include the parameter 'FileFormat:=xlOpenXMLWorkbook' in your SaveAs method. Simply changing the file extension in the filename string is not sufficient and will result in a corrupted or unreadable file.

How can I prevent my VBA loop from processing the newly saved XLSX files?

You can prevent endless processing loops by configuring your 'Dir()' function or conditional logic to strictly filter for files ending specifically in '.xlsm'. Alternatively, you can save the newly generated '.xlsx' files into a completely separate destination folder outside of the loop's scanning directory.