Your use of 'ThisDocument' points the macro to them template itself, not to any document you might open. Your use of Selection also invites errors.
For more efficient code to update document headers & footers, see:
https://www.msofficeforums.com/62942-post2.html