Fix Word VBA Merge Error: Cannot Give Document Same Name as Open Document
Question details
A Visual Basic program used to generate manuals is failing after a Microsoft 365 update, displaying an error that Word cannot give a document the same name as an open document.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Running a VBA macro to perform a document merge and generate an emergency manual after a recent Microsoft 365 suite update.
- Observed behavior
- The macro execution halts and Word throws an error stating it cannot give a document the same name as an open document, preventing the manual from being generated.
Ensure all instances of Microsoft Word and Excel are completely closed, including background processes in the Task Manager, to prevent hidden locked files from conflicting with your macro's save operations.
Debug and Update VBA File Handling Code
Microsoft 365 updates can change how background processes handle file locking. Updating your VBA code to explicitly close documents and handle errors prevents the file naming conflict.
When VBA attempts to save or open a document using the same name as a file that is already open (even invisibly in the background), Word will block the action. You must step through your code to find the exact line causing the conflict and ensure previous instances are properly closed.
Open your macro-enabled document and press ALT + F11 to launch the Visual Basic for Applications (VBA) Editor.
Click inside your macro code and press F8 repeatedly to step through the execution line-by-line until the 'same name' error appears. This identifies the problematic SaveAs2 or Open command.
Right before the line that triggers the error, ensure any previously generated document is closed by adding a line such as: ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges (or specify the exact document object).
At the end of your merge loop, explicitly release your Word and Excel objects by setting them to Nothing (e.g., Set wdApp = Nothing) to prevent ghost processes from keeping files open.

Clear Ghost Word Processes in Task Manager
End any stuck Microsoft Word background tasks that might be holding the target document open from a previous failed macro run.
Try WPS Office for Stable VBA and Macro Execution
If unexpected Microsoft 365 updates continue to break your automated scripts, consider switching to WPS Office. It offers a highly compatible and stable environment for running essential VBA macros without the disruption of forced background updates altering your workflows.

Frequently Asked Questions
Why does Word say I cannot give a document the same name as an open document?
This error occurs when your VBA script attempts to save a new file with a specific name, but a document with that exact name is already open. This is often caused by a hidden background instance of Word holding the file open from a previously crashed macro run.
Can a Microsoft 365 update change how my VBA macros run?
Yes. Office updates frequently alter security settings, background process handling, and occasionally the object model. These changes can cause previously perfectly working VBA macros to suddenly encounter file locking, timing, or permission issues.
How do I prevent file lock errors during a Word mail merge in VBA?
To prevent file locks, ensure your code uses explicit object references rather than relying on ActiveDocument. Always close documents programmatically as soon as you are done with them, and set your COM objects to 'Nothing' before the script finishes.




