Finally found the problem!!!
It was where I was setting the Endnote options to use regular numbers. Turns out if the document was already using this option, me setting it again caused the document to get selected if the script was undone. So I added the following if statement which solved the problem, only changing the option if needed.
Code:
If Not ActiveDocument.Range.EndnoteOptions.NumberStyle = 0 Then
ActiveDocument.Range.EndnoteOptions.NumberStyle = 0
End If