Hi there,
Take a look at the attached version of your workbook and see if it does what you need.
It uses the following code:
Option Explicit
'=========================================================================================
'=========================================================================================
Private Sub Workbook_Open()
Call UpdateInfoSheet(sAction:="ACCESSO")
End Sub
'=========================================================================================
'=========================================================================================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call UpdateInfoSheet(sAction:="FINE SESSIONE")
End Sub
'=========================================================================================
'=========================================================================================
Private Sub UpdateInfoSheet(sAction As String)
Const iCOLUMN__ACTION As Integer = 54
Const iCOLUMN__NAME As Integer = 52
Const iCOLUMN__DATE As Integer = 53
Const sINFO_SHEET As String = "INFO"
Const sPASSWORD As String = "123456"
Dim iNewRowNo As Integer
Dim bSaved As Boolean
bSaved = ThisWorkbook.Saved
With Sheets(sINFO_SHEET)
.Unprotect Password:=sPASSWORD
iNewRowNo = .Cells(Rows.Count, iCOLUMN__NAME).End(xlUp).Row + 1
.Cells(iNewRowNo, iCOLUMN__NAME) = Application.UserName
.Cells(iNewRowNo, iCOLUMN__DATE) = Now
.Cells(iNewRowNo, iCOLUMN__ACTION) = sAction
.Protect Password:=sPASSWORD
End With
ThisWorkbook.Save
ThisWorkbook.Saved = bSaved
End Sub
The highlighted values may be altered to suit your own requirements.
The ThisWorkbook.Saved = bSaved statement will cause the "Do you want to save . . ." prompt to be displayed when appropriate, but in reality it is not required because the workbook will have been saved anyway! It may be useful to leave it in place so that Users do not think that the workbook has been closed without giving them the opportunity to save their work.
Hope this helps - please let me know how you get on.
Spero di averti aiutato
Regards,
Greg M
Bookmarks