Requirement:
How to make a workbook work only on specific days and time.
That is workbook works normally from Monday to Friday as from 8.00 am to 5 pm, otherwise if not in the specified range then read only or close workbook.
Solution:
Place the following code on ThisWorkbook Module.
Private Sub Workbook_Open() If Weekday(Date, vbMonday) = 6 And Weekday(Date, vbMonday) = 7 Then MsgBox "The workbook is only allowed in weekdays.", vbExclamation ThisWorkbook.Close False Else If TimeValue(Now) < TimeValue("08:00:00") Or TimeValue(Now) > TimeValue("17:00:00") Then MsgBox "The workbook is only allowed between 9 AM to 5 PM.", vbExclamation ThisWorkbook.Close False End If End If End Sub
Obtained from the OzGrid Help Forum.
Solution provided by sktneer.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to count cells in a dynamic range matching two criteria given in table headers |
How to COUNTIF using input cell as range depth |
How to select time stamp ranges and assign the correct tour destination |
How to look for value in three different ranges and return one of three results |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.