Is there a way to track who opened an excel file?
I have tried this and it does not work:
Appreciate any help
Sheet called Log with
Open-Close Time Date User
Marco code:
Option Explicit
Private strOpenClose As String
Private strDate As String
Private strTime As String
Private strUser As String
Private strValues As String
Private Const strlogfile As String = "C:\Path\Log.xlsx"
Private Sub Workbook_Open()
strOpenClose = "Opened"
strDate = Format(Date, "dd.mm.yyyy") 'set format to taste
strTime = Format(Time, "HH:MM:SS")
strUser = Environ("username")
strValues = strOpenClose & "', '" & strDate & "', '" & strTime & "', '" & strUser
WriteToWorksheet strWorkbook:=strlogfile, strRange:="Sheet1", strValues:=strValues
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
strOpenClose = "Closed"
strDate = Format(Date, "dd.mm.yyyy")
strTime = Format(Time, "HH:MM:SS")
strUser = Environ("username")
strValues = strOpenClose & "', '" & strDate & "', '" & strTime & "', '" & strUser
WriteToWorksheet strWorkbook:=strlogfile, strRange:="Sheet1", strValues:=strValues
End Sub
Private Function WriteToWorksheet(strWorkbook As String, _
strRange As String, _
strValues As String)
Dim ConnectionString As String
Dim strSQL As String
Dim CN As Object
strRange = strRange & "$]"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strWorkbook & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=YES;"";"
strSQL = "INSERT INTO [Sheet1$] VALUES('" & strValues & "')"
Set CN = CreateObject("ADODB.Connection")
Call CN.Open(ConnectionString)
Call CN.Execute(strSQL, , 1 Or 128)
CN.Close
Set CN = Nothing
End Function
I have tried this and it does not work:
Appreciate any help
Sheet called Log with
Open-Close Time Date User
Marco code:
Option Explicit
Private strOpenClose As String
Private strDate As String
Private strTime As String
Private strUser As String
Private strValues As String
Private Const strlogfile As String = "C:\Path\Log.xlsx"
Private Sub Workbook_Open()
strOpenClose = "Opened"
strDate = Format(Date, "dd.mm.yyyy") 'set format to taste
strTime = Format(Time, "HH:MM:SS")
strUser = Environ("username")
strValues = strOpenClose & "', '" & strDate & "', '" & strTime & "', '" & strUser
WriteToWorksheet strWorkbook:=strlogfile, strRange:="Sheet1", strValues:=strValues
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
strOpenClose = "Closed"
strDate = Format(Date, "dd.mm.yyyy")
strTime = Format(Time, "HH:MM:SS")
strUser = Environ("username")
strValues = strOpenClose & "', '" & strDate & "', '" & strTime & "', '" & strUser
WriteToWorksheet strWorkbook:=strlogfile, strRange:="Sheet1", strValues:=strValues
End Sub
Private Function WriteToWorksheet(strWorkbook As String, _
strRange As String, _
strValues As String)
Dim ConnectionString As String
Dim strSQL As String
Dim CN As Object
strRange = strRange & "$]"
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strWorkbook & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=YES;"";"
strSQL = "INSERT INTO [Sheet1$] VALUES('" & strValues & "')"
Set CN = CreateObject("ADODB.Connection")
Call CN.Open(ConnectionString)
Call CN.Execute(strSQL, , 1 Or 128)
CN.Close
Set CN = Nothing
End Function