Hi all,
I'd appreciate your help with the following please.
Basically I'm trying to protect a workbook after a Date. Then if someone enters the correct password then the workbook becomes unprotected, otherwise if they get the password incorrect, then it protects the workbook till you get it right. The first half of the code appears to be working, however after the "END IF" statements, that's where I go wrong.
Example Code - (almost working)
Sub Workbook_Open()
Dim exdate As Date, ws As Worksheet, PW As String
exdate = "03/08/2017"
If Date > exdate Then
MsgBox ("You have reached the end of your trial period")
PW = InputBox("Enter password:")
If PW = "Password" Then
For Each ws In Worksheets
ws.Unprotect
Next ws
MsgBox ("Password is Correct, Please Proceed")
Exit Sub
End If
End If
For Each ws In Worksheets
ws.Protect
Next ws
MsgBox ("The Password is incorrect, This file is now locked from any further use")
MsgBox ("Contact Support on XXX XXX XXX for the Password")
End Sub
cheers - GreenBolt
I'd appreciate your help with the following please.
Basically I'm trying to protect a workbook after a Date. Then if someone enters the correct password then the workbook becomes unprotected, otherwise if they get the password incorrect, then it protects the workbook till you get it right. The first half of the code appears to be working, however after the "END IF" statements, that's where I go wrong.
Example Code - (almost working)
Sub Workbook_Open()
Dim exdate As Date, ws As Worksheet, PW As String
exdate = "03/08/2017"
If Date > exdate Then
MsgBox ("You have reached the end of your trial period")
PW = InputBox("Enter password:")
If PW = "Password" Then
For Each ws In Worksheets
ws.Unprotect
Next ws
MsgBox ("Password is Correct, Please Proceed")
Exit Sub
End If
End If
For Each ws In Worksheets
ws.Protect
Next ws
MsgBox ("The Password is incorrect, This file is now locked from any further use")
MsgBox ("Contact Support on XXX XXX XXX for the Password")
End Sub
cheers - GreenBolt