Hmm, interesting. Word 2010 is different from Word 2007 in this area.
When you use the Table of Contents gallery in 2007, it just inserts a
TOC heading, the TOC field, and one empty Normal-style paragraph into
the document. When you do the same thing in 2010, it inserts those
three items inside a content control.
I think (but I'm not sure) that content control is why your macro says
the paragraph has no style (technically, the expression
aPara.Range.Style returns the value Nothing and gets the error "Object
variable or With block variable not set").
However, if you replace that expression with aPara.Style, the macro
behaves perfectly.
Or, if you forget about the canned TOCs in the Building Blocks gallery
and instead just insert a TOC field through the Insert > Quick Parts >
Fields dialog, your original macro behaves correctly.
Just another "improvement". Sorry...
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.