How to Run a Word Macro Automatically After Pasting
Question details
The user wants to automatically run a series of formatting procedures via a macro immediately after pasting content (such as Excel data) into a Word document.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Pasting external content into Word and needing to apply custom tabs, weekday formats, and highlighting automatically without triggering multiple manual macros.
- Observed behavior
- Standard Ctrl+V and the Clipboard paste command do not trigger custom macros natively unless the paste action is explicitly intercepted. Behavior also unexpectedly differs depending on whether Backspace or Delete is used prior to pasting.
Ensure your document is saved as a Macro-Enabled Document (.docm) and that the Developer tab is enabled in your ribbon so you can access the VBA editor.
Create a Wrapper Macro to Intercept the Paste Command
By creating a custom macro that executes the paste action and then immediately calls your formatting procedures, you can consolidate the workflow into a single keystroke.
By default, standard paste operations in Word do not trigger custom code. You must write a wrapper macro that manually executes the paste command, followed by your custom formatting calls.
Naming your macro 'EditPaste' will automatically override Word's default paste command, meaning Ctrl+V will run your custom script natively.
Press Alt + F11 to launch the Visual Basic for Applications (VBA) editor in Word.
Insert a new module and define a sub procedure named EditPaste. Type 'Selection.Paste' on the first line.
Below the paste command, use the 'Call' statement to trigger your other macros (e.g., 'Call FormatTabs', 'Call HighlightText').
Return to your document and press Ctrl+V to paste content. Verify that both the paste action and the subsequent formatting procedures run successfully.

Troubleshoot Selection and Insertion Point Issues
If your macro fails to format correctly after pressing Delete instead of Backspace, you need to adjust how your VBA code handles document selection.
Automate Document Workflows with WPS Writer
WPS Office offers robust support for VBA macros, enabling you to seamlessly write, edit, and run custom scripts to automate tasks like pasting and formatting.
- 1. Enable Developer Tools: Open WPS Writer and enable the Developer tab from the options menu to access macro functionalities.
- 2. Open the VBA Editor: Click the 'Macros' or 'Visual Basic' button in the Developer ribbon to launch the scripting environment.
- 3. Write the Wrapper Script: Create a new module and input your custom paste and format VBA code.
- 4. Execute the Macro: Assign your new macro to Ctrl+V or a custom toolbar button to run your workflow instantly.

Frequently Asked Questions
Can I intercept the default Ctrl+V command directly in Word?
Yes, you can intercept the default Ctrl+V command by naming your custom macro 'EditPaste'. Word recognizes this specific name and will execute your macro instead of the default system paste command.
Why does my macro behave differently if I use Delete instead of Backspace?
Pressing Delete removes characters ahead of the cursor, while Backspace removes characters behind it. This alters the starting insertion point and the active document selection. If your macro uses the 'Selection' object to apply formatting, the differing cursor placement can cause the macro to apply formatting to the wrong area or fail.
How do I assign my custom macro to a different keyboard shortcut?
Go to File > Options > Customize Ribbon, and click 'Customize' next to Keyboard shortcuts. Select 'Macros' from the Categories list, choose your macro, click inside the 'Press new shortcut key' box, press your desired combination, and click 'Assign'.
What should I do if my called procedures are not executing?
Check that the called macros actually exist and are accessible. They should not be marked as 'Private' if they are stored in a different module. Also, use a simple MsgBox test inside the main macro to verify the initial paste trigger is working.




