logo
search
VBA & Macro Problems

How to Replace Underlined Words with Answer Choices Using a Word Macro

Amos GikundaAmos Gikunda Oct 7, 2026 871 views

Question details

The user needs to automatically identify underlined text in a document and extract it into multiple-choice answer formats (A, B, C, D) using a macro.

How to Replace Underlined Words with Answer Choices Using a Word Macro
Product
Word
Device & OS
not provided
Scenario
Automating the creation of a quiz by extracting existing underlined keywords into answer options.
Observed behavior
Standard form-field macros fail to process ordinary underlined text. A specialized VBA script is required to locate underlined text runs and replace the target placeholders.
Before you start

Before running any VBA macro, ensure you save a backup copy of your document to prevent accidental data loss during the automated text replacement process.

Solution 1Recommended

Use a VBA Macro Designed for Underlined Text

Implement a custom VBA script that specifically searches for the underline font property rather than form fields, then runs through the document to populate your answer choices.

A common mistake is using a macro designed for form fields to extract regular text. Since ordinary underlined words are not form fields, the macro ignores them, resulting in no changes to your document.

To fix this, the VBA code must specifically iterate through the document's text, check for the Font.Underline property, collect these text strings in order, and then insert them into the placeholders for answers A, B, C, and D.

1
Open the VBA Editor

With your document open, press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the VBA editor, click on 'Insert' in the top menu bar and select 'Module' to create a blank workspace for your script.

3
Paste the Macro Code

Paste your custom VBA script (which searches for Selection.Font.Underline = wdUnderlineSingle) into the new module window.

4
Run the Macro

Close the VBA editor to return to your document. Press Alt + F8, select your newly created macro from the list, and click 'Run'.

Use a VBA Macro Designed for Underlined Text
Check Your Placeholders: Ensure your document is formatted with the exact placeholders (e.g., [A], [B]) that your specific VBA script is programmed to locate and replace.
Efficient Document Automation

Automate Quiz Creation with WPS Writer Macros

WPS Office provides robust macro (VBA) support, allowing you to seamlessly run scripts to extract underlined words and create multiple-choice tests. It handles automation tasks effortlessly while providing a familiar interface.

  1. 1. Open Your Document: Launch WPS Writer and open the document containing the underlined words you want to extract.
  2. 2. Access the Developer Tools: Navigate to the 'Developer' tab on the top ribbon. If it is hidden, enable it in the settings, then click 'Macros' (or press Alt + F8).
  3. 3. Create and Run the Macro: Click 'Create' to open the WPS Macro Editor, paste your VBA script for extracting underlined text, and run it to automatically generate your answer choices.
Fully compatible with Microsoft Word document formats (.docx, .docm).Built-in Macro (VBA) editor to automate complex and repetitive editing tasks.Lightweight application that processes text-heavy scripts quickly and smoothly.Free alternative with a highly intuitive and familiar user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why did nothing happen when I ran the macro?

If nothing happened, your macro might be designed to process form fields instead of ordinary underlined text. You need to ensure the VBA script explicitly searches for the 'Font.Underline' property to identify standard text.

Will this macro delete the original underlined words?

It depends entirely on the VBA script you are executing. You can program the macro to either copy the text (leaving the original underlined words intact) or cut the text to replace it entirely with a blank line for students to fill in.

How do I save a document that contains my new macro?

To preserve the VBA code for future use, you must save the document as a Word Macro-Enabled Document (.docm). Standard Word documents (.docx) cannot store macro scripts and will discard them upon saving.