Move shape anchors away from heading paragraphs

Article contributed by Bill Coan

Problem
When shape anchors are located in heading paragraphs, the table of contents is unable to display heading numbers. This routine works even on shapes whose anchors are locked. It preserves the location of a shape even if the shape is positioned relative to paragraph!

Solution
Cut offending shapes out of the document and paste them back into the document with their anchors at a new location, immediately below the heading paragraph. Do this without affecting the location of the shape on the page.

Sub MoveAnchorsOutOfHeadings()

Dim oShape As Shape

For Each oShape In ActiveDocument.Shapes
    If Left$(oShape.Anchor.Style, 7) = "Heading" Then
        oShape.Select
        Selection.Cut
        Selection.MoveDown unit:=wdParagraph, Count:=1
        Selection.Paste
    End If
Next oShape

End Sub