How to Use a Word VBA Macro to Remove Space After a Paragraph
Question details
The user wants to use a Microsoft Word VBA macro to quickly set the spacing after a selected paragraph to zero.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Streamlining document formatting by using a macro to automatically adjust paragraph spacing rather than clicking through ribbon menus.
- Observed behavior
- The user requires the exact VBA code and instructions on how to implement it to remove trailing space for specific text selections without modifying the underlying paragraph style.
Ensure that the Developer tab is enabled in your Microsoft Word ribbon so you can access the Visual Basic for Applications (VBA) editor.
Create and Run a VBA Macro to Remove Paragraph Spacing
Use a simple VBA script to instantly set the 'Space After' property of selected paragraphs to zero.
This macro applies direct formatting to your current text selection. It safely removes the trailing space from the highlighted paragraphs without modifying the document's built-in paragraph styles.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.
In the VBA editor, click 'Insert' from the top menu bar and select 'Module' to create a new script window.
Copy and paste the following code into the empty module window: Sub RemoveSpaceAfterParagraph() Selection.ParagraphFormat.SpaceAfter = 0 End Sub
Close the VBA editor and return to your document. Highlight the text you wish to format, press Alt + F8, select 'RemoveSpaceAfterParagraph' from the list, and click 'Run'.
To run this macro quickly in the future, navigate to File > Options > Customize Ribbon. Next to 'Keyboard shortcuts', click 'Customize'. Select 'Macros' from the Categories list and assign a preferred shortcut key.

Remove Paragraph Spacing Effortlessly in WPS Writer
While macros are incredibly powerful, WPS Office provides a highly intuitive user interface that allows you to manage paragraph formatting seamlessly without writing a single line of code.
- 1. Select the Target Text: Open your document in WPS Writer and highlight the specific paragraphs you want to modify.
- 2. Open Paragraph Settings: Right-click the selected text and choose 'Paragraph' from the context menu, or navigate to the 'Home' tab and click the Settings icon in the Paragraph group.
- 3. Adjust Spacing After: In the Paragraph dialog box, locate the 'Spacing' section. Change the 'After' value to 0.
- 4. Apply the Changes: Click 'OK' to instantly remove the extra space after the selected paragraphs.

Frequently Asked Questions
Will this VBA macro affect my entire Word document?
No, the code uses the 'Selection' object, which means it will only apply the zero-spacing format to the specific text or paragraphs you have highlighted before running the macro.
How do I save a Word document that contains a macro?
To preserve your VBA macro for future use, you must save your document as a Word Macro-Enabled Document (.docm). Standard .docx files are designed to strip out macro code for security reasons.
Can I modify this macro to remove spacing before a paragraph as well?
Yes. You can easily modify the script by adding or substituting the line 'Selection.ParagraphFormat.SpaceBefore = 0' to remove any spacing situated above the selected paragraphs.
How can I add this macro to the Quick Access Toolbar?
Navigate to File > Options > Quick Access Toolbar. Under the 'Choose commands from' dropdown menu, select 'Macros'. Find your macro in the list, click 'Add', and then click 'OK' to place a clickable macro button on your toolbar.




