on Thisworkbook, put:
Private Sub Workbook_Open()
Call checkPW(True)
End Sub
Then create two other macros in a separate module
Option Explicit
Sub checkPW(Optional firstRun As Boolean)
Dim j, i, trials, passCnt As Integer
trials = 3 'Number of trials
passCnt = 4 'Number of times to enter password
j = 1
ReDim AllPassWords(1 To trials) As String
AllPassWords(1) = "123"
AllPassWords(2) = "456"
AllPassWords(3) = "789"
ReDim ExpDate(1 To trials) As Date 'We pre-define the expiry dates and passwords
ExpDate(1) = CStr(DateSerial(2023, 1, 14) + TimeSerial(8, 49, 0))
ExpDate(2) = CStr(DateSerial(2023, 1, 15) + TimeSerial(8, 51, 0))
ExpDate(3) = CStr(DateSerial(2023, 1, 16) + TimeSerial(8, 53, 0))
Dim PassWord As String 'User password
If CDate(Now) < ExpDate(j) Then 'If the jth trial has not expired we do the following
If j = 1 Then
For i = 1 To passCnt ' chances to enter password
'Enter password before we can use the worksheet
PassWord = InputBox("Please input password.")
If PassWord = AllPassWords(j) Then
Exit For
ElseIf i < passCnt Then
MsgBox "Incorrect password. " & passCnt - i & " attempts remaining."
ElseIf i = passCnt Then
MsgBox "Password limit reached. Closing workbook"
ThisWorkbook.Close
End If
Next i
MsgBox ("You have " & ExpDate(j) - CDate(Now) & " days left")
End If
Else:
If firstRun = True Then
MsgBox "Trial " & j & " has expired. New password will be required to continue"
End If
j = j + 1
End If
Call macro_timer
End Sub
Sub macro_timer()
'Tells Excel when to next run the macro.
Application.OnTime Now + TimeValue("00:00:10"), "checkPW"
End Sub
I used
If firstRun = True Then
MsgBox "Trial " & j & " has expired. New password will be required to continue"
End If
To define what to show only when the workbook is opened, you can adjust as you need