I have a WriteAuditRecord procedure when this is required. It can be used to write entries to an Audit worksheet, or to a .txt file on the network. This sample writes it to a text file:
Public Sub WriteAuditRecord(strComment As String)
'MUST set reference to Windows Script Host Object Model in the project to use this code!
Dim objFS As FileSystemObject
Dim objFile As File
Dim datCurrent As Date
Dim strRecord As String
Dim strFileName As String
strRecord = ThisWorkbook.FullName & " " _
& Format(Now(), "yyyy-mm-dd HH:MM:SS AMPM") & ", " & UserName() & ": " _
& strComment
strFileName = ThisWorkbook.Path & "\J" & Format(Day(Now()), "00") & ".txt"
Open strFileName For Append As #1
Write #1, strRecord
Close #1
Set objFS = New FileSystemObject
Set objFile = objFS.GetFile(strFileName)
objFile.Attributes = Hidden
Proc_Exit:
Set objFile = Nothing
Set objFS = Nothing
End Sub
in a separate module:
Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Function UserName() As String
On Error GoTo Proc_Error
strUserName = Space(255)
If GetUserName(strUserName, Len(strUserName) + 1) Then
strUserName = Trim$(strUserName)
strUserName = Left(strUserName, Len(strUserName) - 1)
UserName = strUserName
Else
UserName = "ErrorName"
End If
Proc_Exit:
Exit Function
Proc_Error:
Select Case Err
Case Else
MsgBox "Error " & CStr(Err) & ": " & Err.Description
Resume Proc_Exit
End Select
Exit Function
End Function
You will need to set a reference to the "Windows Script Host Object Model" to use the FileSystemObjects. In this sample, it creates a new file based on the day of entry, but you can name a specific file as well.
Just call this from the Workbook_Open, Workbook_Close and button_click events with the appropriate comment. You've posted enough here I'm sure you know how to put this in...