In my VBA code, I get a runtime exception (say divide by zero) and after pressing ‘End’ in the error box, the VBA runtime gets stopped.
During this stop, my global Objects are getting cleared. I want these objects to retain their values. Because, when I start over again, since these objects are Nothing, I am having issues.
Is there any event in VBA which will get triggered when my runtime gets stopped?? Or is there any way to know whether VBA is still running or stopped?
In VBA, an unhandled exception clears global variables. So add error handlers to your VBA procedures.
Here is a transcript of a session in the Immediate window, using the 2 procedures included below.
A procedure without an error handler …
A version with an error handler …
However I’m unsure whether including error handlers in your procedures will be enough to preserve your global variable values. I avoid using globals.