If you want a macro to show (with formatting) the equivalent of a contents list for H1 and H2 headings, but with section wordcount figures, not page numbers, I’ve written a macro to do so.
https://www.wordmacrotools.com/macros/W/WordCountByHeading