XLA routines: EE_LogError

Nick's picture
EE_LogError - logs to temp file if no file specified... logs information. Can be used for any logging not just errors - can display a messagebox of the error. - dependent on EE_WriteToTextFile
Sub EE_LogError(strErrMsg As String, strErrSrc As String, blnShowMsgBox As Boolean, _
    Optional strFullPathOrFileName As String, Optional strSheetName As String)
'- takes: error message
'- string: error source
'- boolean whether to show a message box
'- optional file full path / file name
'- optional sheet name
'Logs: now, computername, login, error source, message
'If file full path exists (must be a text file) log to that.. If doesn't exist,
'create it.
'- if just a file name, log to temp dir
'If sheet name exists - log to that

'http://excelexperts.com/xla-routines-eeLogError    for updates on this sub routine

    Dim arrLog
    arrLog = Array(Format(Now, "dd/mmmm/yyyy hhmmss"), EE_GetComputername, EE_GetUsername, strErrSrc, strErrMsg)
    If blnShowMsgBox Then
        MsgBox "Error: " & strErrMsg & vbLf & "Source: " & strErrSrc
    End If
    If strFullPathOrFileName = "" Then
        If strSheetName <> "" Then
            With ThisWorkbook.Worksheets(strSheetName).range("A1")
                .Offset(.CurrentRegion.Rows.Count).Resize(, UBound(arrLog) + 1).value = arrLog
            End With
        End If
        Call EE_WriteToTextFile(Join(arrLog, vbTab), strFullPathOrFileName)
    End If
End Sub