Who is using my excel file
Here is a sample of writing a log file.
Private Sub WriteLog()
' trap error in case network not available
On Error GoTo trap
Dim log As String ' for the text to send to the log file
Dim ff As Long ' for the link to the text file
ff = FreeFile ' get a free file chammel
' create the text for the log
log = Format(Date, "ddd dd-mmm-yyyy") & " BookX opened as "
If ThisWorkbook.ReadOnly Then
log = log & "Read Only."
Else
log = log & "Read Write."
End If
' open the file for append
'note: if the file doesn't exist then it will be created automatically
Open "X:\LogFolder\THISBOOK_LOG.TXT" For Append As ff
' send the text to the log file
Print #ff, log
' then close it
Close #ff
trap: Err.Clear
End Sub
You should be able to modify it to write on opening, write on closing.
Use the Workbook.Open event and the Workbook_BeforeClose event.
You can get the user login name with
uname = CreateObject("Wscript.Network").UserName
or
Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long
Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left(sName, cChars - 1)
End If
End Function
--
Regards,
Tom Ogilvy
"Jez" wrote in message
...
Hi,
I am looking to find out how i can create a text file and log who is using
my excel file, from when they open my file and when they close the file. I
want to log this in a text file showing date and time, who is loging in to
the file, and then the same info when they logout of my file.
Hope someone can help me soon..
Jez.
|