How can I create custom error messages and logging in my VBA code using runtime error handling?

Responsive Ad Header

Question

Grade: Education Subject: Support
How can I create custom error messages and logging in my VBA code using runtime error handling?
Asked by:
95 Viewed 95 Answers

Answer (95)

Best Answer
(393)
Use the `Err.Raise` method to trigger a custom error. Provide a unique error number (e.g., greater than 1000) and a custom description. Inside your error handler, you can then use `Debug.Print` or write to a log file to record details of the error (error number, description, date/time, module, procedure name). Consider including information that will allow the user to re-create the error.