Cat On A Spreadsheet
When building large Excel VBA projects, the way you handle errors can make or break your solution. If errors go unnoticed or leave no trace, debugging becomes guesswork. Advanced projects need more than a quick On Error Resume Next — they need error tracing, logging, and reporting. In this post, we’ll build a reusable ErrorHandler module that:
Traces procedures with a stack.
Collects all errors in memory during a run.
At the end of execution, creates a single timestamped log file.
Emails the log file automatically to the developer for review.
Does nothing if no errors occur.
This makes error handling predictable, auditable, and automated.
Here’s a ready-to-use module. It has three main parts:
Procedure tracing (EnterProc and ExitProc)
Error capturing (LogError)
Log flushing + email (FlushErrors)
Wrap your procedures with structured error handling:
At the end of your main controlling routine, flush all collected errors:
One file per run: Keeps logs tidy and easy to match with sessions.
Complete context: Each error has a timestamp, user, machine, and procedure stack.
Automatic reporting: Developers get notified immediately with the full log.
Zero noise if no errors: No empty files or pointless emails.
Error-proofing large VBA projects is about more than avoiding runtime crashes. With centralized logging, stack tracing, and automated developer alerts, you’ll always know what went wrong, where, and why — without relying on users to describe the problem. This module is a strong foundation, and you can extend it further with features like severity levels, unique error IDs, or integration with bug trackers.
Cat On A Spreadsheet