Consulting

Results 1 to 5 of 5

Thread: Solved: Need to log macro errors

  1. #1
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location

    Solved: Need to log macro errors

    As to avoid relying on users to report macro error handled messages to the administrator, I'd like to also log the error type, date and time to a hidden sheet.

    Does anyone use a method such as that and have a pre-written code sample they would be willing to share ?

    Thanks

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If VBA error messages are suppressed, how is the user to know that their results are wrong?

  3. #3
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    HI mikerickson,

    Sorry that I didn't explain well. - I'm not suppressing errors. I have error handlers that report to the user with a message box. I just don't want to to rely on the user to report the error to me. -- The only reason I want the log sheet hidden is because some users get the bright idea that they are better off if I am not made aware that they have been experiencing errors.

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Add a hidden worksheet to the workbook and add code to your error handler logging the error and the routine that errored.
    Something like
    [vba]Sub mySubOne()
    On Error Goto Handler
    ' code
    Exit Sub
    Handler:
    With ThisWorbook.Sheets("error Log").Range("A65536").End(xlup).Offset(1,0)
    .Cells(1,1) = Now
    .Cells(1, 2) = Err
    .Cells(1, 3) = Error
    .Cells(1, 4) = "mySubOne"
    End With
    ' handle error
    Exit Sub[/vba]

  5. #5
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Perfect - Exactly what I was after

    Thanks mikerickson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •