Sub error_rec(error_msg, error_macro_name) '<---- macro pass variables
On Error GoTo error_rec_fail
If error_msg = Null Or error_msg = "" Or error_msg = 0 Or error_msg = Empty Or error_macro_name = Null Or error_macro_name = "" Or error_macro_name = 0 Or error_macro_name = Empty Then
GoTo error_rec_fail
Else: End If
todays_date_time = Format(Now, "MM/DD/YYYY HH:MM Am/Pm")
user_name = VBA.Interaction.Environ$("UserName") 'Currently Logged In User Name
'Index Columns
err_date_time_index = ThisWorkbook.Sheets("Macro Error Log").ListObjects("macro_errors").ListColumns("Error Date and Time").Index
err_macro_name_index = ThisWorkbook.Sheets("Macro Error Log").ListObjects("macro_errors").ListColumns("Error Macro ID Name").Index
err_user_name_index = ThisWorkbook.Sheets("Macro Error Log").ListObjects("macro_errors").ListColumns("User Name").Index
err_details_index = ThisWorkbook.Sheets("Macro Error Log").ListObjects("macro_errors").ListColumns("Error Details").Index
'Count active rows
err_record_count = ThisWorkbook.Sheets("Macro Error Log").Range("macro_errors").ListObject.ListRows.Count
If err_record_count = 0 Then
err_new_record_row = 2
Else: err_new_record_row = err_record_count + 2
End If
ThisWorkbook.Sheets("Macro Error Log").Cells(err_new_record_row, err_date_time_index).Value = todays_date_time
ThisWorkbook.Sheets("Macro Error Log").Cells(err_new_record_row, err_user_name_index).Value = user_name
ThisWorkbook.Sheets("Macro Error Log").Cells(err_new_record_row, err_macro_name_index).Value = error_macro_name
ThisWorkbook.Sheets("Macro Error Log").Cells(err_new_record_row, err_details_index).Value = error_msg
GoTo end_macro
error_rec_fail:
MsgBox "An unknown error has occured and cannot be recorded to the Macro Error Log." & Chr(13) & Chr(13) & "Please contact the macro Administrator if this problem occurs again.", vbCritical + vbOKOnly, "A CRITICAL ERROR HAS OCCURRED"
end_macro:
End Sub