VBA (Microsoft build-in scripting language) will help here. With it, you
The code would be:
I've tested it with a default template, and it successfully deleted all empty headings, effectively cleaning up the Table of Contents.
sub RemoveEmptyHeadings()
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
If para.Style = "Heading 1" And _
para.Range.Characters.Count <= 1 Then
para.Range.Delete
End If
Next para
End Sub
The only counter intuitive code piece is that an empty paragraph is not empty - it has one newline character (causes <= 1 condition).
The quickest way to use this code in a document
Reuse this code
When you're done with the setup, close the VBA window. The RemoveEmptyHeadings
is now accessible as a macro (custom-built little program). One of the ways you can access macros is by pressing alt+f8 and selecting the needed one from the window that appears.
You can also use macros by adding buttons to the Word Quick Access, or assigning keyboard shortcuts. The web describes how to achieve that.