Option
Explicit
Public
Sub
logFile(
ByVal
Action
As
String
,
Optional
Sheet
As
String
,
Optional
ByVal
Target
As
String
,
Optional
ByVal
Value
As
String
)
Dim
strLogFile
As
String
, strTmp
As
String
, strOld
As
String
Dim
strAction
As
String
* 15
Dim
strSh
As
String
* 12
Dim
strAddr
As
String
* 12
Const
strSep
As
String
=
", "
strLogFile = ThisWorkbook.Path & Application.PathSeparator & ThisWorkbook.Name &
"_log.txt"
strTmp = Format(Now,
"dd.MM.yyyy hh:mm:ss"
)
strTmp = strTmp & strSep
strAction = Action
strTmp = strTmp & strAction & strSep
If
Len(Sheet)
Then
strSh = Sheet: strTmp = strTmp & strSh & strSep
If
Len(Target)
Then
strAddr = Target: strTmp = strTmp & strAddr & strSep
If
Len(Value)
Then
strTmp = strTmp & Left(Value, 1024)
If
Right(strTmp, Len(strSep)) = strSep
Then
strTmp = Left(strTmp, Len(strTmp) - Len(strSep))
Open strLogFile
For
Binary
As
#1
strOld = Space$(LOF(1))
Get
#1, , strOld
Close #1
strTmp = strTmp & vbCrLf & strOld
Open strLogFile
For
Output
As
#1
Print #1, strTmp
Close #1
End
Sub