How to Automatically Create a List of Questions in Word with VBA
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.

- 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.
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.
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.
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.
Press 'Alt + F11' to open the Visual Basic for Applications (VBA) editor. Click 'Insert' > 'Module' to create a blank module for your code.
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.
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.
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.

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. Enable Macros: Open your document in WPS Writer and navigate to the Developer tab to access the Macro and VBA tools.
- 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. 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.

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.




