How to Select a Heading and Body Text Until the Next Heading in Word
Question details
The user wants to select a specific heading where the cursor is currently placed, along with all the subsequent body text, stopping exactly before the next heading begins.
- Product
- Word
- Device & OS
- not provided
- Scenario
- Editing a document and needing to quickly highlight or extract a section of content nested under a specific heading.
- Observed behavior
- Looking for an automated or built-in way to achieve this using a VBA macro or Word Outline View.
Ensure your document is formatted with built-in heading styles (e.g., Heading 1, Heading 2), as both VBA macros and Outline View rely on these styles to properly identify document sections.
Use a VBA Macro to Select the Current Heading Section
Use a simple VBA macro to automatically select the heading where your cursor is located and all its subordinate content.
By utilizing Word's built-in bookmark system for heading levels, a short VBA script can instantly highlight the current section.
This method is highly efficient for repetitive tasks or when processing large documents.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
In the top menu, click 'Insert' and then select 'Module' to create a blank workspace.
Copy and paste the following code into the module window: Sub Demo() Selection.GoTo What:=wdGoToBookmark, Name:="\HeadingLevel" Selection.Select End Sub
Place your cursor inside the target heading or its body text in your document, then return to the VBA editor and press F5 to run the macro.
Select Heading Content Using Outline View
Use the built-in Outline View to easily select a heading and all the text under it without using code.
Easily Manage Headings and Content in WPS Writer
WPS Writer offers full compatibility with Microsoft Word documents, including heading styles, Outline View, and advanced formatting tools. It allows you to organize and select document sections effortlessly.
- 1. Open the Document: Launch WPS Writer and open your document containing the headings.
- 2. Access Outline View: Go to the 'View' tab and click on the 'Outline' button.
- 3. Select the Content: Click the structural icon next to any heading to highlight the entire section at once.
- 4. Use the Navigation Pane: Alternatively, open the Navigation Pane from the View tab to quickly jump between headings or select sections.

Frequently Asked Questions
Why does the VBA macro select more text than expected?
If the macro selects text past what you expect, check your document's formatting styles. The macro selects content until it encounters the next heading of the same or higher level. Ensure the subsequent section is properly formatted with a heading style.
Can I select a heading and its content without Outline View or VBA?
Yes, you can use the Navigation Pane. Go to View > Navigation Pane, locate the desired heading in the list, right-click it, and choose 'Select Heading and Content'.
Does this VBA macro work in WPS Office?
Yes, WPS Office supports VBA macros in its professional editions. You can run the exact same `wdGoToBookmark` code in the WPS VBA editor to achieve the same result.
What happens if my cursor is in the middle of a paragraph?
If your cursor is anywhere within the body text under a heading, running the macro will automatically identify the parent heading above it and select that heading along with all associated body text up to the next equivalent heading.




