logo
search
Document Editing Problems

How to Automatically Create a List of Questions in Word with VBA

Chanuka GeekiyanageChanuka Geekiyanage Oct 1, 2026 868 views

Question details

The user needs to automate the process of extracting specific marked questions from a Word report and compiling them into a list at the end of the document.

How to Automatically Create a List of Questions in Word Using VBA
Product
Word
Device & OS
not provided
Scenario
Consolidating a list of specific questions scattered throughout a long report into one dedicated section.
Observed behavior
Questions marked with phrases like 'see conclusion' are currently being copied and pasted manually to the end of the document.
Before you start

Ensure the Developer tab is enabled in your ribbon to access the VBA editor, and verify that your document is saved as a Macro-Enabled Document (.docm) so your VBA script is retained.

Solution 1Recommended

Use a Custom Paragraph Style and VBA Macro

Tag each question with a dedicated custom style, then run a VBA macro that automatically scans the document, extracts these paragraphs, and compiles them at the bottom.

By relying on a specific paragraph style rather than plain text search, you ensure that only the exact questions you intend to extract are pulled into your summary list. This method is cleaner and reduces extraction errors.

1
Create a 'Question' Style

Navigate to the Home tab, open the Styles pane, and click 'New Style'. Name the style 'Question' and apply it to every question paragraph in your report.

2
Open the VBA Editor

Press 'Alt + F11' to open the Visual Basic for Applications (VBA) editor. Click 'Insert' > 'Module' to create a blank module for your code.

3
Write the Extraction Script

Write a VBA script that loops through 'ActiveDocument.Paragraphs'. Inside the loop, check if the paragraph's style matches 'Question'. If it does, store the text of that paragraph in a string variable.

4
Output the Compiled List

In the same script, add code to navigate to the end of the document using 'Selection.EndKey Unit:=wdStory', insert a 'List of Questions' heading, and paste the compiled text variable. Include a safeguard block to check if the 'List of Questions' section already exists to prevent duplicate scanning on subsequent runs.

5
Run the Macro

Close the VBA editor, press 'Alt + F8', select your new macro from the list, and click 'Run'. The extracted questions will instantly be generated at the end of your document.

Use a Custom Paragraph Style and VBA Macro
Macro Safeguard: To prevent generating duplicate lists, you can program the macro to find the 'List of Questions' header and delete all text below it before regenerating the new list.
Automate Formatting with WPS Writer

Run VBA Macros Seamlessly in WPS Office

WPS Writer provides robust support for VBA macros, allowing you to automate repetitive tasks like compiling questions, styling reports, and extracting text efficiently.

  1. 1. Enable Macros: Open your document in WPS Writer and navigate to the Developer tab to access the Macro and VBA tools.
  2. 2. Apply Custom Styles: Use the Styles pane on the Home tab to create a unique style for your questions and apply it across your report.
  3. 3. Execute the Script: Click 'Macros' in the Developer tab, paste your VBA extraction code into the editor, and run it to automatically generate your question list.
Fully compatible with Microsoft Word macro-enabled files (.docm).Built-in VBA editor makes it easy to script and automate complex document tasks.Powerful styling tools to help you organize and extract specific report sections quickly.
microsoft office alternative - wps office

Frequently Asked Questions

How do I show the Developer tab to access VBA?

Go to File > Options > Customize Ribbon. Check the box next to 'Developer' in the right-hand column and click OK. The Developer tab will now appear in your main ribbon menu, giving you access to the Visual Basic editor.

Can I use VBA to extract text containing a specific phrase instead of relying on styles?

Yes. You can use the 'Find' object in VBA to search for trigger phrases like 'see conclusion'. Once the script finds the phrase, it can select the entire sentence or paragraph and append it to your compiled list at the end of the document.

Why does my macro disappear after closing the document?

Standard Word documents (.docx) cannot save macro code due to security restrictions. You must use 'Save As' and choose the 'Word Macro-Enabled Document (.docm)' format to ensure your VBA scripts are saved for future editing and execution.