How to Fix Excel VBA Run-Time Error 53 When Renaming PRN Files
Question details
The user needs a reliable way to prevent a macro from failing when trying to rename a recently created PRN file before the system has fully finished saving it.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- A VBA macro is generating a PRN file through a print dialog and immediately executing a rename command on that file.
- Observed behavior
- The macro throws a Run-time error 53 (File not found) because the file creation process has not completed by the time the rename command runs.
Verify that the file path and file name specified in your VBA script exactly match the directory where the PRN file is being saved.
Pause Code Execution Using Application.Wait
Introduce a brief, hardcoded delay in your macro to allow the operating system enough time to finish creating and saving the PRN file before proceeding.
Because file saving operations can take a few moments depending on the system's speed, VBA code often outpaces the file creation. Adding a specific wait time forces the script to hold off until the file is ready.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window, and locate your active macro module.
Scroll through your code to find the exact line where the 'Name' statement is being used to rename the PRN file.
Add the following line of code immediately above the Name statement: Application.Wait (Now + TimeValue("0:00:15")). You can adjust the 15 seconds to a shorter duration if your system processes the file faster.
Save your code and run the macro again. The script will now pause for the specified time, ensuring the file is fully generated before the rename is attempted.

Use a Dir() Function Loop to Verify File Existence
Dynamically check if the file has been created using a loop instead of waiting for a fixed amount of time.
A Powerful and Free Alternative for Your Spreadsheet Needs
If you frequently encounter macro errors, performance bottlenecks, or simply need a highly efficient spreadsheet tool, consider trying WPS Office. It provides a lightweight, exceptionally compatible environment designed to make data processing tasks smooth and reliable.
- 1. Download the Installer: Visit the official WPS Office website and click on the Free Download button.
- 2. Install WPS Office: Run the downloaded installation file and follow the on-screen prompts to set up the software.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing workbooks to experience seamless compatibility.

Frequently Asked Questions
Why does Run-time error 53 occur in Excel VBA?
This error occurs when a VBA function—such as the Name statement, Kill, or Open—attempts to access, rename, or delete a file that does not exist at the specified directory path. In automated workflows, this often happens if the code executes faster than previous file-creation steps.
Is DoEvents alone enough to fix the file not found error?
Using DoEvents by itself is often insufficient for file creation delays because it only briefly yields execution to the operating system. If the file takes several seconds to generate, the script will resume too quickly. Combining it with a Dir() loop or using an explicit Application.Wait is much more reliable.
Can I use a shorter wait time than 15 seconds for Application.Wait?
Yes. The TimeValue can be easily adjusted to suit your system's performance. You can reduce it to 5 seconds (TimeValue("0:00:05")) or even shorter, depending on how quickly your computer generates and saves the PRN file.




