How to Convert Word Chapter Headings to Styles Using VBA
Question details
The user wants to convert manually numbered chapter headings and TC (Table of Contents Entry) fields into proper built-in Heading styles using a VBA macro.
- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Automating the formatting of legacy documents that use manual numbering and TC fields instead of standard structural styles.
- Observed behavior
- The document currently relies on manual numbering and TC fields for chapter headings, preventing automatic updates. The goal is to programmatically apply standard heading styles based on the TC field levels and remove the old fields.
Before running any VBA macro, ensure you save a backup copy of your document to prevent unintended formatting loss, and enable the Developer tab to access the Visual Basic editor.
Use a VBA Macro to Replace TC Fields with Heading Styles
Create a VBA macro to find TC fields, read their level indicators, apply the corresponding heading style to the paragraph, and remove the field.
TC fields contain level codes that indicate whether they should be Heading 1, 2, or 3. A macro can locate these fields, apply the appropriate style to the containing paragraph, and safely delete the manual TC field.
Note that if the text in the TC field differs from the actual paragraph text, this approach assumes you want the existing paragraph text to appear in your generated Table of Contents instead.
Press ALT + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor in your word processor.
In the project pane on the left, right-click your document name, hover over Insert, and select Module to create a new workspace for your macro.
Write a script that loops through the ActiveDocument.Fields collection, checking if the field type is wdFieldTOCEntry to identify the TC fields.
Within your loop, extract the level code from the field's text, apply the matching wdStyleHeading1, wdStyleHeading2, etc., to the field's parent paragraph, and then execute the .Delete method on the field.
Press F5 to run the macro. Once it finishes processing, carefully review the document to ensure styles were applied to the correct paragraphs.
Configure Multilevel Lists for Automatic Numbering
Link your newly applied heading styles to a multilevel list to automatically generate and maintain chapter numbers.
Format Chapter Headings and Generate TOCs with WPS Writer
WPS Writer offers an intuitive interface to apply heading styles, set up multilevel list numbering, and automatically generate a Table of Contents seamlessly, while fully supporting advanced VBA macros.
- 1. Apply Heading Styles: Open your document in WPS Writer. Select your chapter title, navigate to the Home tab, and click Heading 1 or Heading 2 from the Styles gallery.
- 2. Set Up Numbering: To add automatic numbering, click the Multilevel List icon on the Home tab and select a predefined heading-linked list style.
- 3. Generate the Table of Contents: Go to the References tab and click Table of Contents to automatically generate a navigation block based on your newly applied styles.

Frequently Asked Questions
Why should I use Heading styles instead of manual numbering?
Heading styles allow word processors to automatically build a Table of Contents, populate the navigation pane, and maintain consistent formatting across your entire document, which manual numbering cannot do.
What is a TC field in a document?
A TC (Table of Contents Entry) field is a hidden formatting mark used to manually define text and heading levels that should appear in a Table of Contents, typically used when the TOC text needs to differ from the actual document heading.
Can I batch process multiple Word documents with a VBA macro?
Yes, you can use specialized VBA batch processing scripts or third-party add-ins to loop through all documents in a specific folder and apply your macro to each one automatically.
Will converting TC fields to styles alter my Table of Contents?
Yes. If the original TC field contained custom text that differed from the paragraph text, generating a new TOC based on heading styles will use the exact text from the paragraph instead of the TC field's custom text.




