Hello everyone.
The attached macro creates a txt file to control who opens the workbook.
Also automatically creates the directory must is the txt file.
You can change the third option:
I change something in the workbook then I choose no in the excel warning
and in the txt file it must be unmodified
I hope I explained myself
The attached macro creates a txt file to control who opens the workbook.
Also automatically creates the directory must is the txt file.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Urec As String
Dim path As String
Dim name1 As String
Dim CurFolder, DestFolder As String
'---------------------------------------------------------------------------
'username accesso/chiusura all'avvio/chiusura
name1 = Foglio1.Range("A1").Value
CurFolder = ActiveWorkbook.path
DestFolder = CurFolder & "\" & name1 & "\"
If Dir(DestFolder, vbDirectory) = "" Then MkDir DestFolder
Open DestFolder & "\accessi_ACTIONLIST_C.log" For Append As #1
'Open path & "\accessi_PROVA.log" For Append As #1
If ThisWorkbook.Saved = False Then
Urec = Cells(Rows.Count, 1).End(xlUp).Row + 1
Print #1, Application.UserName, Now & " CHIUSURA MODIFICATO"
Print #1, "-------------------------------------------------"
Close #1
ElseIf ThisWorkbook.Saved = True Then
Urec = Cells(Rows.Count, 1).End(xlUp).Row + 1
Print #1, Application.UserName, Now & " CHIUSURA NON MODIFICATO "
Print #1, "-------------------------------------------------"
Close #1
Else
ThisWorkbook.Close False
'file non modificato
Print #1, Application.UserName, Now & " CHIUSURA NON MODIFICATO "
Print #1, "-------------------------------------------------"
Close #1
'End If
'End If
End If
'--------------------------------------------------------------------------
End Sub
You can change the third option:
Code:
Else
ThisWorkbook.Close False
'file non modificato
Print #1, Application.UserName, Now & " CHIUSURA NON MODIFICATO "
Print #1, "-------------------------------------------------"
Close #1
'End If
I change something in the workbook then I choose no in the excel warning
and in the txt file it must be unmodified
I hope I explained myself