Hello everyone.
In the attached workbook there are macros in thisworkbook:
in Private Sub Workbook_Open()
'---------------------------------------------------------------------------
'ACCESSI
Dim nomefoglio As Variant
Dim Urec As String
Application.ScreenUpdating = False
Application.EnableEvents = False '<-aggiunta
'With Sheets("ACCESSI")
' nomefoglio = .Cells(10000, "II")
' Sheets(nomefoglio).Activate '<<< apre il foglio e sprotegge
With Sheets("ACCESSI") '<<< apre il foglio e sprotegge
.Unprotect "987654"
.Cells(10000, "II") = ActiveSheet.Name
.Unprotect "987654"
'Urec = .Cells(Rows.Count, 52).End(xlUp).Row + 1
'.Cells(Urec, 52) = Application.UserName
'.Cells(Urec, 53) = Now
'.Cells(Urec, 54) = "ACCESSO"
Urec = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(Urec, 1) = Application.UserName
.Cells(Urec, 2) = Now
.Cells(Urec, 3) = "ACCESSO"
.Protect "987654"
End With
Application.ScreenUpdating = True
Application.EnableEvents = True '<-aggiunta
'---------------------------------------------------------------------------
and in:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'---------------------------------------------------------------------------
'ACCESSI
Dim nomefoglio As Variant
Dim Urec As String
Application.ScreenUpdating = False
Application.EnableEvents = False '<-aggiunta
With Sheets("ACCESSI") '<<< apre il foglio e sprotegge
.Unprotect "987654"
.Cells(10000, "II") = ActiveSheet.Name
'Urec = .Cells(Rows.Count, 52).End(xlUp).Row + 1
'.Cells(Urec, 52) = Application.UserName
'.Cells(Urec, 53) = Now
'.Cells(Urec, 54) = "FINE SESSIONE"
Urec = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(Urec, 1) = Application.UserName
.Cells(Urec, 2) = Now
.Cells(Urec, 3) = "FINE SESSIONE"
.Protect "987654"
End With '<<< ritorna al foglio
ThisWorkbook.Save 'salva
If SoloVisione = True Then ThisWorkbook.Saved = False 'se ci sono stati interventi proponi popup Salva
Application.ScreenUpdating = True
Application.EnableEvents = True '<-aggiunta
'------------------------------------------------------------------------------------------------------
which are used to enter in the "ACCESSI" sheet whoever accesses the workbook.
Also in this workbook there is a macro:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'------------------------------------------------------------------------------------------------------
'per utente autorizzato
Dim avviso As String
Dim cercarange As Range
Set cercarange = Foglio8.Range("E2:E11").Find(Foglio8.Range("F2"))
If cercarange Is Nothing Then
' MsgBox "Value not found"
avviso = MsgBox(Environ("UserName") & " non sei autorizzato a modificare questo workbook", vbCritical + vbDefaultButton2, "AVVISO!")
If avviso = vbOK Then
Me.Saved = True
Exit Sub
' MsgBox "Value not found"
'ThisWorkbook.Saved = True
' ThisWorkbook.Close
Else
'MsgBox foundRng.Address
End If
End If
'---------------------------------------------------------------------------
to authorize the use of the workbook to certain users who are in the sheet "utenti_errori" column E
There is a problem:
if changes are made and at closing I say "do not save" these changes remain.
Help to correct?
I hope I have explained.
xam
Bookmarks