'----------------------------------------------------------------------- 'per username - chi apre Sheets("Utenti_Errori").Unprotect "987654" Sheets("Utenti_Errori").Cells(2, 6).Value = Environ("UserName") 'F2 Sheets("Utenti_Errori").Protect "987654" '------------------------------------------------------------------------
ThisWorkbook.Save
Option Explicit Public SoloVisione As Boolean Sub a() SoloVisione = False End Sub
Dim val1 As String Dim val2 As String Dim val3 As String '========================================================= Call a '============================================================ '--------------------------------------------------------------------------- '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 = False Then ThisWorkbook.Saved = False 'se ci sono stati interventi proponi popup Salva Else ThisWorkbook.Save End If '========================================================================================
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim name1 As String, name2 As String, name3 As String, name4 As String, name5 As String Dim sPath As String, sComm5 As String, sComm6 As String, sComm7 As String, sComm8 As String Dim fogli As Worksheet Dim iUserResponse As Integer Dim risposta1 As String Dim risposta2 As String Dim risposta3 As String Dim sStatus As String Dim val1 As String Dim val2 As String Dim val3 As String '--------------------------------------------------------------------------- '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 '------------------------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------------------------ 'per utente autorizzato Dim avviso As String Dim cercarange As Range Set cercarange = Foglio8.Range("E2:E11").Find(Foglio8.Range("F2")) If Not cercarange Is Nothing Then 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 Else ' 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 End If End If ' MsgBox "Value not found" 'ThisWorkbook.Saved = True ' ThisWorkbook.Close '--------------------------------------------------------------------------- '--------------------------------------------------------------------------- Application.ScreenUpdating = False '------------------------------------------------------------------------------------------ 'backup name5 = Foglio11.Range("A2").Value sComm5 = "BACKUP" sComm6 = Foglio11.Range("A2").Value sComm7 = sComm6 'Foglio6.Range("B3").Value sComm8 = sComm5 & " - " & sComm6 'Foglio6.Range("B3").Value If MsgBox("Sign. " & Environ("UserName") & " vuoi il backup di:" & Chr(13) & Chr(13) & _ "< " & sComm6 & " >?", vbQuestion + vbYesNo + vbDefaultButton2, "AVVISO!") = vbYes Then sPath = ThisWorkbook.Path & "\" & sComm8 If Dir(sPath, vbDirectory) = "" Then MkDir sPath 'sPath = sPath & "\" & sComm7 'If Dir(sPath, vbDirectory) = "" Then MkDir sPath 'sPath = sPath & "\" & sComm6 'If Dir(sPath, vbDirectory) = "" Then MkDir sPath ThisWorkbook.SaveCopyAs sPath & "\" & Format(Now, "dd-mm-yyyy - hh.mm") & " - " & ActiveWorkbook.Name '<<< data/ora End If ' End If '-------------------------------------------------------------------------- '-------------------------------------------------------------------------- ' '-------------------------------------------------------------------------- Application.ScreenUpdating = True End Sub
Private Sub Workbook_Open() Dim fogli As Worksheet Dim Ur As Long '----------------------------------------------------------------------- 'per username - chi apre Sheets("Utenti_Errori").Unprotect "987654" Sheets("Utenti_Errori").Cells(2, 6).Value = Environ("UserName") 'F2 '========================================= ThisWorkbook.Save '============================================ Sheets("Utenti_Errori").Protect "987654" '------------------------------------------------------------------------
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" '========================================= ThisWorkbook.Save '============================================ .Protect "987654" End With
'--------------------------------------------------------------------------- '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" '========================================= ThisWorkbook.Save '============================================ .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 '============================================================================= If SoloVisione = False Then ThisWorkbook.Saved = False 'se ci sono stati interventi proponi popup Salva Else ThisWorkbook.Save End If '========================================================================================
rollis13:1) salvare il dato su un altro file esterno al progetto