View Full Version : Excel Access Log VBA

05-08-2012, 04:24 AM

I'm trying to record users who access excel documents.

However instead of recording the data in a seperate sheet in the same workbook, i want the data to log in a completely different workbook.

Is this possible?

The code i have as my starting point is:

Private Sub Workbook_Open()
Sheets("Access log").Activate
If Range("A1").Value = "" Then
n = 1
n = Cells(Rows.Count, "A").End(xlUp).Row + 1
End If
Cells(n, "A").Value = Environ("username")
Cells(n, "b").Value = Date
Cells(n, "c").Value = Time
Sheets("Access log").Activate
End Sub

Any help would be appreciated!:bug:

05-08-2012, 05:10 AM
Private Sub Workbook_Open()
Dim lngFile As Long
dim strFilename as string
lngFile = FreeFile

strfilename = "C:\Logfile.txt"

Open strFilename For Append As lngFile

Print #lngFile, Environ("username"); ";";
Print #lngFile, format(date(),"YYYYMMDD"); ";";
Print #lngFile, format(Now(),"HHMMSS")

Close lngFile
end sub

This will write a log to a text file. Perhaps this would be a solution for you.