• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

macro check control

max_max

New Member
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.


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
 
Hi !​
Max_Max : this is a wild cross posting so Read this !
As you already get an aswer in another forum use Cancel = False if you want to not close …​
 
Hi marc I don't have the third option does not work
Code:
 Else
    
     ThisWorkbook.Close False
    
        'file non modificato
        Print #1, Application.UserName, Now & " CHIUSURA NON MODIFICATO "
        Print #1, "-------------------------------------------------"
        Close #1
        Cancel = True
    'End If
 
As we can't check without any link of your original thread as explained in my previous post link and read this forum rules :​
 
Back
Top