How to track who viewed excel file

Status
Not open for further replies.

FLdave12

Board Regular
Joined
Feb 4, 2022
Messages
78
Platform
  1. Windows
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
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Duplicate to: How to track who opens excel workbook

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,225,739
Messages
6,186,738
Members
453,369
Latest member
juliewar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top