You can add an On Error
check at any level, including your Sub Main
. Any errors that are not caught by an error check at that functions level will rise through the call stack to the main/initial method where you could there catch them.
You could then gracefully display the error (so you or your users are aware of it) and then resume whatever method is best at that point. And, remember, you can do this at several different strategic levels and locations.
If the errors occur in an event procedure, then these won't be trapped in Sub Main()
so you will also need to catch them there.
Any errors that rise to the top of the stack, either out of Sub Main()
or an event procedure will be caught by the runtime and are fatal. Your code will get no notification of this.
You may also be interested in the post Good Patterns For VBA Error Handling.