Excel VBA

css navigation by Css3Menu.com

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-2024

Updated:  01/23/2024 13:34
This page added:  21 May 2003