Append text to log file
At work I once maintained 3 workbooks on a shared drive with stop statistics. Two of the statistics were basically identical, and I dislike doing unnecessary work.
I also suspected that nobody used the data in the third workbook, so I decided to log if any other user than myself opened the workbook.
After quite some time the log had no entries at all, so I told my boss about it and said that I intended to stop maintaining the workbook.
He laughed and said okay. After all he could hardly insist on me wasting time.
Below is the simple macro that does the job by appending text to a text file. For the code to work, the text file "log.txt" must exist in the same folder as the workbook, but you can easily change that.
To copy the code highlight it with the mouse, press CTRL+C and paste it into a VBA module with CTRL+V.
Sub auto_open()
AppendToTextFile
End Sub
Sub AppendToTextFile()
Dim fs, f
Dim sPath As String
If Application.UserName = "Eric Bentzen" Then Exit Sub
On Error Resume Next
sPath = ThisWorkbook.Path & "\log.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sPath, 8)
f.Write vbNewLine & Now & " " & Application.UserName
f.Close
End Sub
Related:
|