Copy to the ThisWorkbook code module.
Private Sub Workbook_Open()
Dim lRow As Long
Dim c As Range
With Worksheets("Log")
Set c = .Cells.Find(Application.UserName)
If Not c Is Nothing Then
lRow = c.Row
Else
lRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End If
.Cells(lRow, 1) = "Opened"
.Cells(lRow, 2) = Application.UserName
.Cells(lRow, 3) = Format(Now, "dd-mm-yyyy hh:mm:ss")
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lRow As Long
Dim c As Range
With Worksheets("Log")
Set c = .Cells.Find(Application.UserName)
If Not c Is Nothing Then
lRow = c.Row
Else
lRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End If
.Cells(lRow, 1) = "Closed"
.Cells(lRow, 2) = Application.UserName
.Cells(lRow, 3) = Format(Now, "dd-mm-yyyy hh:mm:ss")
End With
ThisWorkbook.Save
End Sub
Bookmarks