VBA & Macro Problems

How to Intercept Save and Save As Commands with Word VBA

John WilsonJohn Wilson Oct 26, 2026 869 views

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.

How to Intercept Save and Save As Commands with Word VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) Editor.

2
Access the ThisDocument Module

In the Project Explorer pane on the left, expand your document's project and double-click 'ThisDocument' to open its code window.

3
Create the FileSave Intercept

Type 'Sub FileSave()' and press Enter. Inside this procedure, add your custom logic (e.g., checking if the document has a path).

4
Create the FileSaveAs Intercept

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'.

5
Save the VBA Code

Click the Save icon in the VBA Editor and return to your document to test the intercepted commands.

Use Exact Macro Names in the ThisDocument Module
Bypass Save As Prompt for Existing Files: To prevent a prompt when a document already has a saved path, you can use: If Len(ActiveDocument.Path) > 0 Then ActiveDocument.Save: Exit Sub.
Customize Documents with WPS Writer

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. 1. Open the Document: Launch WPS Writer and open your target document.
  2. 2. Access the VBA Editor: Go to the 'Developer' tab on the top ribbon and click 'VBA Editor' (or press Alt + F11).
  3. 3. Insert the Intercept Code: Double-click 'ThisDocument' in the Project Explorer and paste your FileSave and FileSaveAs code.
  4. 4. Save as Macro-Enabled: Go to Menu > Save As, and choose 'Macro-Enabled Document (*.docm)' to preserve your custom VBA intercepts.
Full support for writing and executing VBA macrosHighly compatible with Microsoft Word macro-enabled formats (.docm, .dotm)Lightweight application with a familiar user interfaceCost-effective solution for advanced document automation
QA img-9

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.