Option Explicit
Private Sub Workbook_Open()
Application.ScreenUpdating = False
If Hour(Now) = 21 Then
Sheets("log").unprotect password:="this is a secret"
With Sheets("log").Range("A56000").End(xlUp).Offset(1)
.Value = Date & " " & Time
.Offset(, 2).Value = Date & " " & Time
.Offset(, 3).Value = "complete"
.Offset(, 4).Value = "Auto Open"
.Offset(, 5).Value = Environ("USERNAME")
End With
Sheets("log").Protect password:="this is a secret"
SuggestBOMS
getcosts
Me.Close True
Application.Quit
Else
Sheets("log").unprotect password:="this is a secret"
With Sheets("log").Range("A56000").End(xlUp).Offset(1)
.Value = Date & " " & Time
.Offset(, 2).Value = Date & " " & Time
.Offset(, 3).Value = "complete"
.Offset(, 4).Value = "Manual Open"
.Offset(, 5).Value = Environ("USERNAME")
End With
Sheets("log").Protect password:="this is a secret"
End If
End Sub
'Private Sub Workbook_BeforePrint(Cancel As Boolean)
'Application.ScreenUpdating = False
'If Cancel = False Then'
'
' Sheets("log").unprotect password:="this is a secret"
'With Sheets("log").Range("A56000").End(xlUp).Offset(1)
' .Value = Date & " " & Time
' .Offset(, 2).Value = Date & " " & Time
' .Offset(, 3).Value = "complete"
' .Offset(, 4).Value = "Print " & ActiveSheet.Name
' .Offset(, 5).Value = Environ("USERNAME")
'
'End With
' Sheets("log").Protect password:="this is a secret"
'End If
'End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.ScreenUpdating = False
Dim WS As Worksheet
If Sheets("input").Shapes("Button 15").TextFrame.Characters.Text <> "Admin Mode" Then
For Each WS In Worksheets
WS.Visible = True
WS.unprotect password:="this is a secret"
Next WS
Sheets("input").Shapes("Button 15").TextFrame.Characters.Text = "Admin Mode"
With Sheets("log").Range("A56000").End(xlUp).Offset(1)
.Value = Date & " " & Time
.Offset(, 3).Value = "incomplete"
.Offset(, 4).Value = "Save & Exit Admin"
.Offset(, 5).Value = Environ("USERNAME")
.Offset(, 2).Value = Date & " " & Time
.Offset(, 3).Value = "complete"
End With
For Each WS In Worksheets
If WS.Name <> "Input" Then
WS.Visible = False
WS.Protect password:="this is a secret"
End If
Next WS
Sheets("Report").Visible = True
Else
Sheets("log").unprotect password:="this is a secret"
With Sheets("log").Range("A56000").End(xlUp).Offset(1)
.Value = Date & " " & Time
.Offset(, 3).Value = "incomplete"
.Offset(, 4).Value = "Save"
.Offset(, 5).Value = Environ("USERNAME")
.Offset(, 2).Value = Date & " " & Time
.Offset(, 3).Value = "complete"
End With
End If
End Sub
Sub WorkBook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Dim WS As Worksheet
If Sheets("input").Shapes("Button 15").TextFrame.Characters.Text <> "Admin Mode" Then
' Sheets("input").Shapes("Button 15").TextFrame.Characters.Text = "Admin Mode"
For Each WS In Worksheets
WS.Visible = True
WS.unprotect password:="this is a secret"
Next WS
With Sheets("log").Range("A56000").End(xlUp).Offset(1)
.Value = Date & " " & Time
.Offset(, 3).Value = "incomplete"
.Offset(, 4).Value = "Exit & Exit Admin"
.Offset(, 5).Value = Environ("USERNAME")
.Offset(, 2).Value = Date & " " & Time
.Offset(, 3).Value = "complete"
End With
For Each WS In Worksheets
If WS.Name <> "Input" Then
WS.Visible = False
WS.Protect password:="this is a secret"
End If
Next WS
Sheets("Report").Visible = True
Else
Sheets("log").unprotect password:="this is a secret"
With Sheets("log").Range("A56000").End(xlUp).Offset(1)
.Value = Date & " " & Time
.Offset(, 3).Value = "incomplete"
.Offset(, 4).Value = "Exit"
.Offset(, 5).Value = Environ("USERNAME")
.Offset(, 2).Value = Date & " " & Time
.Offset(, 3).Value = "complete"
End With
Sheets("log").Protect password:="this is a secret"
End If
End Sub