Based on a Conditional Compile Argument ErrLog=1 (for all relevant code lines!) the error handler should write an error log file where each entry represents a display of an error message. The structure of an entry should look as follows:
["Error-at-"<datetime>]
Type="Application Error"|"VB Runtime Error"|...
Number=
Description=
SourceApplication=.
SourceErrObject=<Err.Source>
Info=
Reply=
The log file should preferably written by the PrivateProfile functions see WritePrivateProfileString, see GetPrivateProfikeString
Private Declare Function GetPrivateProfileStringA Lib _
"Kernel32" (ByVal strSection As String, _
ByVal strKey As String, ByVal strDefault As String, _
ByVal strReturnedString As String, _
ByVal lngSize As Long, ByVal strFileNameName As String) As Long
Private Declare Function WritePrivateProfileStringA Lib _
"Kernel32" (ByVal strSection As String, _
ByVal strKey As String, ByVal strString As String, _
ByVal strFileNameName As String) As Long
Private Function WritePrivateProfileString32(ByVal strFileName As String, _
ByVal strSection As String, ByVal strKey As String, _
ByVal strValue As String) As Boolean
The <workbook-basename.>Error.log file should be maintained in the folder where the Workbook/VB-Project resides.
This is a simple code scheme to log errors:
Sub ErrLog(sType As String, sSource As String, sDetails As String)
Dim sFilename As String
sFilename = "C:\temp\logging.txt"
' Archive file at certain size
If FileLen(sFilename) > 20000 Then
FileCopy sFilename _ ,
Replace(sFilename, ".txt", Format(Now, "ddmmyyyy hhmmss.txt"))
Kill sFilename
End If
' Open the file to write
Dim filenumber As Variant
filenumber = FreeFile
Open sFilename For Append As #filenumber
Print #filenumber, CStr(Now) & "," & sType & "," & sSource _
& "," & sDetails & "," & Application.UserName
Close #filenumber
End Sub
Based on a Conditional Compile Argument
ErrLog=1(for all relevant code lines!) the error handler should write an error log file where each entry represents a display of an error message. The structure of an entry should look as follows:["Error-at-"<datetime>]
Type="Application Error"|"VB Runtime Error"|...
Number=
Description=
SourceApplication=.
SourceErrObject=<Err.Source>
Info=
Reply=
The log file should preferably written by the PrivateProfile functions see WritePrivateProfileString, see GetPrivateProfikeString
The <workbook-basename.>Error.log file should be maintained in the folder where the Workbook/VB-Project resides.
This is a simple code scheme to log errors: