Fix a Word Macro That Applies Heading 1 but Omits It from the Table of Contents
Question details
The user needs a Word macro to apply the actual Heading 1 style to marked text so it appears in the table of contents.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A macro processes text between HEADING and ENDHEADING markers.
- Observed behavior
- The text looks like Heading 1, but Word identifies the paragraph as Normal and excludes it from the table of contents.
Check that each HEADING and ENDHEADING marker and its heading text are in the same paragraph. The replacement removes the markers and applies Heading 1 to the paragraph.
Apply Heading 1 with a wildcard Find and Replace macro
Use this macro to replace marked text with the captured heading and assign the actual Heading 1 style.
Formatting text to look like a heading does not necessarily change its paragraph style. This macro assigns Heading 1 during replacement so Word can use it in a style-based table of contents.
In Word, open the Developer tab and select Visual Basic. In the editor, choose Insert > Module.
Paste this code into the module: Sub ApplyMarkedHeadings() With ActiveDocument.Content.Find .ClearFormatting .Replacement.ClearFormatting .Text = "HEADING(*)ENDHEADING" .Replacement.Text = "\1" .Replacement.Style = wdStyleHeading1 .Forward = True .Wrap = wdFindStop .Format = True .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End Sub
Return to Word, choose Developer > Macros, select ApplyMarkedHeadings, and click Run. Check a changed paragraph on the Home tab to confirm that Heading 1 is selected.
Click the table of contents, choose Update Table, and select Update entire table.

Apply Heading 1 with Word's Find and Replace dialog
Use the same wildcard replacement manually if you prefer not to run a macro.
Work with headings and contents in WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for editing documents and managing headings. Its Microsoft Word format compatibility helps you move existing documents into WPS Writer; it does not fix a Microsoft Word macro.

Frequently Asked Questions
Why does my heading look correct but not appear in the table of contents?
The paragraph may have visual formatting but still use the Normal style. Click the paragraph and check the Styles gallery on the Home tab; apply Heading 1 if it is not selected.
How do I update the table of contents after applying Heading 1?
Click the table of contents, select Update Table, and choose Update entire table to include newly styled headings.
What does the wildcard replacement do to the markers?
The search HEADING(*)ENDHEADING captures the text between the markers. Replacing it with \1 keeps the captured text and removes both markers.
What if Heading 1 is still missing after I update the table?
Check that the paragraph uses Heading 1, then review the table's settings under References > Table of Contents > Custom Table of Contents. Confirm that Heading 1 is included in the table of contents options.




