Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Èùåì ïîñëåäíþþ ñòðî÷êó â ëîãå
lastrow = Worksheets("log").Range("A60000").End(xlUp).Row
'Çàíîñèì äàòó-âðåìÿ âûõîäà èç ôàéëà
If lastrow > 1 Then
Worksheets("log").Cells(lastrow, 3) = Now
End If
'Ñêðûâàåì âñå ëèñòû êðîìå ëèñòà "ïðåäóïðåæäåíèå"
Worksheets("предупреждение").Visible = True
For Each sh In ActiveWorkbook.Worksheets
    If sh.Name = "предупреждение" Then
        sh.Visible = True
        Else
        sh.Visible = xlSheetVeryHidden
    End If
Next sh
'ñîõðàíÿåìñÿ ïåðåä âûõîäîì
ActiveWorkbook.Save
End Sub

 

Private Sub Workbook_Open()
'Èùåì ïîñëåäíþþ ñòðî÷êó â ëîãå
lastrow = Worksheets("log").Range("A60000").End(xlUp).Row
'Çàíîñèì èìÿ ïîëüçîâàòåëÿ è äàòó-âðåìÿ âõîäà â ôàéë
Worksheets("log").Cells(lastrow + 1, 1) = Environ("USERNAME")
Worksheets("log").Cells(lastrow + 1, 2) = Now
'îòîáðàæàåì âñå ëèñòû
For Each sh In ActiveWorkbook.Worksheets
    sh.Visible = True
Next sh
'ñêðûâàåì ëèñòû "ïðåäóïðåæäåíèå" è "log"
Worksheets("предупреждение").Visible = xlSheetVeryHidden
Worksheets("log").Visible = xlSheetVeryHidden
End Sub

Ведение лога открытия файла

Advertisements