The code actually deletes the found text, but the TOC does not insert at the beginning of the text that has now been deleted. The text "Insert Table of Contents Here" only appears once in the document.
You might ask why not just put the TOC in the document from the beginning, but this is a document that starts off with two sections which would mean two TOCs. I have found how to build two TOC within one document by using named ranges, but probably not going to work with all users.
Code: Select all
Sub FindAndReplaceWithTOC()
With ActiveDocument.Range.Find
.Text = "Insert Table of Contents Here"
.Replacement.Text = ""
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
Call TableOfContents
End Sub