How to Intercept Save and Save As Commands with Word VBA
Question details
The user needs to intercept the standard Save and Save As commands in a Word VBA template but encounters issues where FileSaveAs fails to trigger.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Customizing document save behaviors using VBA macros to override default application commands.
- Observed behavior
- FileSave successfully intercepts the Save command, but FileSaveAs fails to intercept the Save As command due to incorrect procedure naming or wrong module placement.
Ensure your document is saved as a Macro-Enabled Template (.dotm) or Macro-Enabled Document (.docm) and that macros are enabled in your application's Trust Center settings.
Use Exact Macro Names in the ThisDocument Module
Correctly name your procedures FileSave and FileSaveAs without spaces, and place them in the ThisDocument module to ensure they intercept the default commands.
To successfully intercept Word's built-in commands, the macro names must exactly match the internal command names. Any deviation, such as adding spaces, will result in a standard macro rather than an interceptor.
Press Alt + F11 to open the Visual Basic for Applications (VBA) Editor.
In the Project Explorer pane on the left, expand your document's project and double-click 'ThisDocument' to open its code window.
Type 'Sub FileSave()' and press Enter. Inside this procedure, add your custom logic (e.g., checking if the document has a path).
Below the first macro, type 'Sub FileSaveAs()' and press Enter. Add the code you wish to execute when the user selects 'Save As'. Do not use spaces like 'File SaveAs'.
Click the Save icon in the VBA Editor and return to your document to test the intercepted commands.

Run VBA Macros Seamlessly in WPS Office
WPS Office provides robust VBA support, allowing you to easily write, edit, and run macros to customize Save behaviors just like in Microsoft Word.
- 1. Open the Document: Launch WPS Writer and open your target document.
- 2. Access the VBA Editor: Go to the 'Developer' tab on the top ribbon and click 'VBA Editor' (or press Alt + F11).
- 3. Insert the Intercept Code: Double-click 'ThisDocument' in the Project Explorer and paste your FileSave and FileSaveAs code.
- 4. Save as Macro-Enabled: Go to Menu > Save As, and choose 'Macro-Enabled Document (*.docm)' to preserve your custom VBA intercepts.

Frequently Asked Questions
Why is my FileSaveAs macro not triggering?
This usually happens if the macro is named incorrectly (e.g., containing spaces like 'File SaveAs') or if the code is placed in a standard module instead of the specific 'ThisDocument' module.
Can I conditionally skip the Save As dialog using VBA?
Yes. You can check if the document already has a saved path using `If Len(ActiveDocument.Path) > 0`. If true, you can force a standard save (`ActiveDocument.Save`) and exit the sub before the dialog appears.
Do these VBA intercepts work in WPS Office?
Yes, WPS Office supports VBA macros. You can intercept commands using the exact same procedure names (FileSave and FileSaveAs) within the WPS VBA Editor environment.




