Sorry but its not clear what error you are experiencing
The code works without error as an add-in.
Its not intended that you add the code to a form load event in another app
The error handling you added isn't going to work as you intend
If there is an error, the code will never reach the Resume...