Rather than trying to decipher your code, I've updated my own to handle footnotes and endnotes. See:
https://www.msofficeforums.com/word-...ure-index.html
If you want to continue developing your own code, my updated code (which has required a substantial re-write in some respects) should give you a good idea of what's required.