VBA & Macro Problems

How to Prevent Word from Underlining Descenders Using VBA

Olivia MillerOlivia Miller Oct 10, 2026 872 views

Question details

The user needs a method to selectively remove underlines from descender letters (q, y, p, j, g) to prevent the underline from crossing through the bottom of the characters.

How to Prevent Word from Underlining Descenders Using VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Formatting document text for better typography and aesthetics where standard underlining makes descender letters look messy.
Observed behavior
Microsoft Word applies a continuous underline that strikes directly through the descending tails of letters like q, y, p, j, and g, with no built-in setting to avoid this.
Before you start

Ensure your document is saved as a Macro-Enabled Document (.docm) to retain the VBA code, and highlight the text you want to modify before running the macro.

Solution 1Recommended

Remove Underlines from Descenders Using a VBA Macro

Run a custom VBA script to automatically scan selected text and remove the underline formatting specifically from descender characters.

Since Microsoft Word lacks a native toggle to skip descenders when underlining, using a Visual Basic for Applications (VBA) macro is the most efficient workaround. This script iterates through your highlighted text and clears the underline formatting only for the letters q, y, p, j, and g.

1
Open the VBA Editor

Open your Word document and press 'Alt + F11' on your keyboard to launch the Microsoft Visual Basic for Applications window.

2
Insert a New Module

In the top menu, click 'Insert' and select 'Module' to create a new blank module space for your code.

3
Paste the VBA Code

Copy and paste the following code into the blank module window: Sub RemoveUnderlinesBelowDescenders() For Each oChar In Selection.Characters If oChar Like "[qypjg]" Then oChar.Font.Underline = wdUnderlineNone Next oChar End Sub

4
Run the Macro

Close the VBA Editor. Highlight the underlined text in your document, press 'Alt + F8' to open the Macros dialog, select 'RemoveUnderlinesBelowDescenders', and click 'Run'.

Remove Underlines from Descenders Using a VBA Macro
Typography Tip: If you prefer a non-VBA alternative that avoids descenders altogether, consider selecting your text and applying a 'Bottom Border' from the Paragraph menu instead of a standard underline.
Free Microsoft Office alternative

Upgrade Your Document Editing with WPS Office

If dealing with VBA macros and formatting limitations in Microsoft Word is slowing you down, try WPS Office. It provides a highly compatible, lightweight alternative with powerful built-in formatting tools to make document creation effortless.

  1. 1. Download and Install: Visit the official WPS Office website to download and install the free software on your device.
  2. 2. Open Your Document: Launch WPS Writer and click 'Open' to seamlessly load your existing Word documents.
  3. 3. Edit and Format Easily: Enjoy smooth text editing, typography adjustments, and formatting with familiar and highly intuitive tools.
Fully compatible with Microsoft Word (.docx, .docm) and other Office formats.Lightweight installation with incredibly fast document loading speeds.Familiar, user-friendly interface with no steep learning curve.Free to use with comprehensive text formatting and typography features.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Word underline the bottom of letters like 'y' and 'g'?

By default, Microsoft Word's underline formatting applies a continuous line directly under the baseline of the text. Because descender letters (like y, g, p, q, and j) dip below this baseline, the standard underline strikes straight through them.

How do I save a Word document that contains a macro?

Documents containing VBA macros must be saved as a Word Macro-Enabled Document (.docm). If you save it as a standard .docx file, Word will discard the macro code, and you will not be able to run it again in the future.

Will this VBA macro run automatically as I type?

No, the provided VBA macro is designed to run manually on selected text. You must first highlight the text you want to format and then run the macro via the Developer tab or the Macros menu (Alt + F8).

Is there a way to underline text without crossing descenders without using macros?

Yes. Instead of using the standard Underline tool, you can select your text, go to the Paragraph settings group on the Home tab, and apply a 'Bottom Border'. This border naturally sits lower than the descenders, keeping the text highly legible.