logo
search
VBA & Macro Problems

How to Use a Word VBA Macro to Remove Space After a Paragraph

Camila MilosovichCamila Milosovich Oct 16, 2026 869 views

Question details

The user wants to use a Microsoft Word VBA macro to quickly set the spacing after a selected paragraph to zero.

How to Use a Word VBA Macro to Remove Space After a Paragraph
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.
Before you start

Ensure that the Developer tab is enabled in your Microsoft Word ribbon so you can access the Visual Basic for Applications (VBA) editor.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.

2
Insert a Standard Module

In the VBA editor, click 'Insert' from the top menu bar and select 'Module' to create a new script window.

3
Paste the Macro Code

Copy and paste the following code into the empty module window: Sub RemoveSpaceAfterParagraph() Selection.ParagraphFormat.SpaceAfter = 0 End Sub

4
Run the Macro

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

5
Assign a Keyboard Shortcut (Optional)

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.

Create and Run a VBA Macro to Remove Paragraph Spacing
Macro Execution Successful: The selected paragraphs will now have zero trailing space, saving you from manually adjusting the layout for each paragraph.
Efficient Document Formatting

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. 1. Select the Target Text: Open your document in WPS Writer and highlight the specific paragraphs you want to modify.
  2. 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. 3. Adjust Spacing After: In the Paragraph dialog box, locate the 'Spacing' section. Change the 'After' value to 0.
  4. 4. Apply the Changes: Click 'OK' to instantly remove the extra space after the selected paragraphs.
Fully compatible with Microsoft Word document formats (.docx and .doc).Intuitive paragraph layout tools for rapid formatting adjustments.Supports advanced VBA and macros in professional editions.Lightweight, feature-rich, and completely free for standard office tasks.
microsoft office alternative - wps office

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.