How to Save a Copy of an Active Word Document Using a VBA Macro
Question details
The user wants to use a VBA macro in Word to save a duplicate of the currently active document in the exact same folder with a modified filename, such as prepending 'Copy_of_'.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating automated backups or duplicates of an active document using macros without overwriting the original file.
- Observed behavior
- The user needs a script to successfully save a duplicate file with a new name while ultimately leaving the original document unchanged.
Ensure that your Developer tab is enabled to access the VBA Editor, and verify that your current document has been saved at least once so it has a valid directory path.
Use VBA Script to Save a Document Copy
Create a macro that identifies the current document's path, constructs a new filename, and uses the SaveAs method to create a duplicate.
By utilizing the ActiveDocument properties, you can accurately capture the file's current location and name. The SaveAs method will generate the new file, but since it makes the new file active, the script should handle returning to the original document.
Press ALT + F11 on your keyboard to open the VBA Editor in your Word application, then click on 'Insert' and select 'Module' to create a blank script window.
In your script, use 'ActiveDocument.Path' to identify the current folder and 'Application.PathSeparator' to build the new file path. Append your desired prefix, like 'Copy_of_', to 'ActiveDocument.Name'.
Use the 'SaveAs' or 'SaveAs2' method to save the document to the newly constructed file path.
Temporarily disable screen updating by setting 'Application.ScreenUpdating = False'. After the duplicate is saved, use VBA to reopen the original document path and close the copied version so your workspace remains unchanged.

Run VBA Macros to Duplicate Documents in WPS Office
WPS Office provides robust VBA macro support, allowing you to run scripts that automatically save and manage document copies effortlessly.
- 1. Download and Install WPS Office: Download WPS Office and install the version that includes robust VBA macro support.
- 2. Open your Document in WPS Writer: Launch WPS Writer and open the document you wish to duplicate using macros.
- 3. Access the Developer Tools: Navigate to the Developer tab on the ribbon to open the VBA Editor and write or paste your duplication macro.
- 4. Execute the Macro: Run your script to instantly save a modified duplicate in your preferred folder while maintaining your workflow.

Frequently Asked Questions
Why does the macro fail with a 'Path not found' error?
This error occurs if the active document has never been saved before. The 'ActiveDocument.Path' property requires the file to exist on your drive. Save the document manually at least once before running the duplication macro.
Can I automatically add a date stamp to the copied file's name?
Yes, you can modify the VBA script to append a date string, such as 'Format(Date, "yyyy-mm-dd")', to the filename variable before executing the SaveAs method.
How do I prevent the macro from switching my active window to the new copy?
When you use the SaveAs method, Word automatically makes the new file the active document. To prevent disruption, your macro should store the original document's path as a string, execute the SaveAs command, reopen the original file using 'Documents.Open', and finally close the newly copied document.




