How to Remove Underlining from Trailing Spaces in Word
Question details
The user needs to remove underlining from blank spaces at the end of hyperlinks or underlined text without altering the formatting of the actual words.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Finalizing document formatting where hyperlinks or emphasized text accidentally include an underlined blank space at the end.
- Observed behavior
- Trailing spaces following hyperlinks or underlined words incorrectly inherit the underline formatting, creating an unappealing extended line.
Make sure to save a backup copy of your document before running any VBA macros, as macro executions cannot easily be undone using the standard Undo feature.
Use a VBA Macro to Clear Trailing Underlines
Because Word's Find and Replace tool struggles to reliably isolate and modify trailing spaces adjacent to formatted text, utilizing a VBA macro is the most effective automated solution.
This macro specifically targets the final space in a string of underlined text or a hyperlink, trims it, and replaces it with a normal, non-underlined space.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications window.
Click on 'Insert' in the top menu, then select 'Module' to open a blank script window.
Paste your preferred macro script designed to loop through hyperlinks and standard text to trim trailing spaces. (Usually found in Word MVP forums or formatting guides).
Press F5 or click the 'Run' button. The macro will scan the document and remove the underline from the trailing spaces.

Manually Remove Underline from Spaces
For shorter documents with only a few instances of extended underlines, manually highlighting and removing the format is often faster than setting up a macro.
Fix Formatting Issues Easily with WPS Office
WPS Writer offers an intuitive interface and precise formatting tools, making it exceptionally easy to manage hyperlinks, text styles, and hidden characters without needing complex macros.
- 1. Open your Document in WPS Writer: Launch WPS Office and open your .docx file containing the formatting issues.
- 2. Reveal Blank Spaces: Click the 'Show/Hide Editing Marks' icon on the Home tab so you can clearly see the trailing space characters.
- 3. Select and Clear Formatting: Highlight the unwanted trailing space, then click the Underline icon (or press Ctrl + U) to instantly clear the underline formatting from just that space.

Frequently Asked Questions
Why does the underline extend past my text?
This happens when you press the spacebar immediately after typing an underlined word while the underline formatting is still active. The word processor assumes you want to continue underlining the next characters, including spaces.
Can I use Find and Replace to fix trailing underlines?
Using the standard Find and Replace tool is generally unreliable for this specific task. The tool struggles to differentiate between a space that is part of a formatted string and one that isn't, often leading to inconsistent results.
How do I prevent trailing spaces from being underlined in the future?
The easiest way to prevent this is to toggle off the underline formatting (by pressing Ctrl + U) immediately after typing the last letter of your word, before pressing the spacebar to start the next word.
Does this issue affect printed documents or just the digital display?
Underlined trailing spaces will appear on the printed document as well. It's best practice to remove them to ensure your final printed or exported PDF document looks professional and clean.




