Hi,

I've been looking all over the internet but heaven't found a solution.

I'm trying to insert a Table of Contents (TOC) in a Word 2010 .docx document whith a macro script from an Excel 2010 .xlsm workbook.

Im doing a Mail Merge from a .docx template (Form_1.docx) and save the document as a merged letter under an other name. I merge several fields including some Header1,2 and 3 fields. I want to include all the headers in a TOC.

I need to insert the TOC after the Mail Merge is done, because a TOC will not include the headers that were filled during the Mail Merge and the TOCs (that are in the template before the merge) can't be updated in the new document after the Mail Merge.


This is a part of my code:

Please Login or Register  to view this content.
The code above doesn't work, it selects the text "<TableOfContentsHere>" in the document perfectly, but myrange gives an error:

Run-time error '450':
Wrong number of arguments or invalid property assignment
So I used the "Normal" TOC macro it works but places the TOC in the begining when i use "Set rangeWord = ActiveDocument.Range(Start:=0, End:=0)". So I tried to place the TOC exacly at the text "<TableOfContentsHere>" in the template document. This works but the "Start range" can differ based on the data that will be merged in the fields. I mean it's not always 458.

Please Login or Register  to view this content.
I need to set the range in my first example to the current selection in the document "<TableOfContentsHere>"

I wil be very gratefull if somebody could provide me a solution.

Regards,