Excel VBA

Excel VBA
Excel Formulas
User-defined Functions
Office Links
Access VBA
Access SQL
Alan’s Excel FAQ
Excel Home
Alan’s Home

Write Error to Log

This goes with the example Trap Those Errors. Told you that the error could be written to file but did not tell you how.

Remember to do an “Exit Sub” inside your code before the Error Handler so that the Handler is not invoked each time your macro runs.

    Exit Sub
ErrHandler:
    Open "ErrorLog.log" For Append As #2    'Open file
        Print #2, Application.Text(Now(), "mm/dd/yyyy HH:mm") _
   ; Error(Err); Err   'Write data
    Close #2      'Close
    Exit Sub      'Exit
End Sub

Open the file for Append, lay down the error date and message and close it again.

© 2003-2011

Updated:  09/11/2011 15:58
This page added:  21 May 2003