Sub Macro1()
Dim boolExist As Boolean
On Error GoTo MY_ERROR_STATE
Range("X56X").Select
MsgBox "OK"
Exit Sub
MY_ERROR_STATE:
boolExist = myfunct_CreateErrorLog(Application.DefaultFilePath)
Err.Raise Err.Number
End Sub
Function myfunct_CreateErrorLog(argERRORLOG_PATH As String, Optional argSQL_COMMAND As String) As Boolean
Dim myFSO_Objeect As Object
If IsNull(argERRORLOG_PATH) = True Then
Exit Function
End If
If Len(argERRORLOG_PATH) = 0 Then
Exit Function
End If
Set myFSO_Objeect = CreateObject("Scripting.FileSystemObject")
If myFSO_Objeect.FolderExists(argERRORLOG_PATH) = False Then
Exit Function
End If
Set myFSO_Objeect = Nothing
Open argERRORLOG_PATH & "\ErrLog.txt" For Output As #1
Print #1, Format(Now, "yyyy/mm/dd h:mm:ss")
Print #1, Application.OperatingSystem
Print #1, "Office " & Application.Version
Print #1, Err.Number
Print #1, Err.Description
Print #1, argSQL_COMMAND
Close #1
End Function