A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
OK, here is code that you would need to put into the "ThisWorkbook" event processor for each workbook in the folder that you wanted to track. What it does is that instead of writing to a sheet in the workbook (you can throw away LogSheet now), it writes to a text file which I've chosen to give a .csv filetype notation to (LogFile.csv) that will either be created (the first time anyone opens a workbook after you implement this code in a workbook) or will append to that file after it has been created. It makes records in the file like this:
"Opened:","F:\JLATHAM\ExcelWork\TestFolder\Logit.xls","JLatham","Wednesday, May 18, 2011 13:44"
"Changed:","F:\JLATHAM\ExcelWork\TestFolder\Logit.xls","JLatham","Wednesday, May 18, 2011 13:46"
Now the slick thing about that file is that you can open it with any text editing file such as NOTEPAD, or by its format and .csv name, you can even open it in Excel and it will put the type of action (opened/changed) into column A, the filename into column B, the username into column C and the date/time (as text, not real date time) into column D. Now it's easy for you to group by specific file to see who has been into it, who made changes to it, or who is accessing which files by filtering/sorting the data.
Here is the new code.
Private Sub Workbook_Open()
Const logFile = "LogFile.csv"
Dim logFileName As String
Dim fileBuffer As Integer
logFileName = ThisWorkbook.Path & Application.PathSeparator & logFile
fileBuffer = FreeFile()
'just in case their is a log jam caused by multiple users
'trying to access the log file at the same time
'ignore the error (record may not be written to the txt file)
'but this file won't crash on them because of it either
On Error Resume Next
Open logFileName For Append As fileBuffer
Print #fileBuffer, Chr$(34) & "Opened:" & Chr$(34) & "," & Chr$(34) & ThisWorkbook.FullName & Chr$(34) & "," _
& Chr$(34) & Application.UserName & Chr$(34) & "," & Chr$(34) & Format(Now(), "dddd, mmmm dd, yyyy hh:mm") & Chr$(34)
Close #fileBuffer
If Err <> 0 Then
Err.Clear
End If
On Error GoTo 0 ' let system or other error trapping function normally
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Const logFile = "LogFile.csv"
Dim logFileName As String
Dim fileBuffer As Integer
Static changeRecorded As Boolean
If changeRecorded Then
Exit Sub
End If
'just in case their is a log jam caused by multiple users
'trying to access the log file at the same time
'ignore the error (record may not be written to the txt file)
'but this file won't crash on them because of it either
On Error Resume Next
logFileName = ThisWorkbook.Path & Application.PathSeparator & logFile
fileBuffer = FreeFile()
Open logFileName For Append As fileBuffer
Print #fileBuffer, Chr$(34) & "Changed:" & Chr$(34) & "," & Chr$(34) & ThisWorkbook.FullName & Chr$(34) & "," _
& Chr$(34) & Application.UserName & Chr$(34) & "," & Chr$(34) & Format(Now(), "dddd, mmmm dd, yyyy hh:mm") & Chr$(34)
Close #fileBuffer
If Err <> 0 Then
Err.Clear
Else
changeRecorded = True
End If
On Error GoTo 0 ' let system or other error trapping function normally
End Sub