countryfan_nt
Well-known Member
- Joined
- May 19, 2004
- Messages
- 765
Hello friends, hope all is well!
Can you please help me with the code below:
I want the code to close the workbook if:
1. UserName is NOT Johnny Case AND
2. Between times 17:45 and 17:59 OR
3. Between times 07:45 and 07:59
The code is placed below; thank you very much in advance!
Can you please help me with the code below:
I want the code to close the workbook if:
1. UserName is NOT Johnny Case AND
2. Between times 17:45 and 17:59 OR
3. Between times 07:45 and 07:59
The code is placed below; thank you very much in advance!
Code:
Private Sub Workbook_Open()
' ===== Environ User Name validation ====
Dim nm As String
nm = UCase(Application.UserName)
time = Now
If nm = "Johnny Cash" or If Time => TimeValue("17:45:00") And Time <= TimeValue("17:59:00") or If Time => TimeValue("07:45:00") And Time <= TimeValue("07:59:00") Then
Sheets("MAIN").Range("N1").Value = "Yes" Then
Sheets("MAIN").Select
Range("A1").Select
Application.Wait (Now + TimeValue("0:00:05"))
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=False
Else
Sheets("Sheet1").Select
Range("A1").Select
End If
End Sub