Lock Workbook upon opening based on current date

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello All,

I have a Excel sheet that I need to lock from editing if the current date is past 3/31/16. however if there is a "password" typed into "Setup!A12" then this would be ignored, then the code would need to see if the date has passed 7/31/16 then check "Setup!A12" for a different password, then a third time for with a different password and 12/31/16.
Also I'd like to have a message box appear in each of the options. However, if there is no value in A12 then I would like "message A" and if there is an incorrect value in A12, then I would like to type a different custom message.

I hope this makes sense and this is doable!


Thanks

Andrew
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
maybe start with this
Code:
Sub test()
If Sheets("setup").Range(A12) = "password1" Then
ActiveSheet.Protect Password:="password"
Exit Sub
End If
If Sheets("setup").Range(A12) = "password2" Then
ActiveSheet.Protect Password:="password"
Exit Sub
End If
If Sheets("setup").Range(A12) = "password3" Then
ActiveSheet.Protect Password:="password"
Exit Sub
End If

End Sub
 
Upvote 0
I don't think that's quite what I'm looking for. When the user opens the workbook this code should run a check and if the the date is passed my set date then it will check if the passcode is correct in A12, if it is, then nothing happens, and if not then the workbook is locked and unable to use (I figured I can hide all the sheets and protect the structure so that the sheets can't be accessed). This check repeats itself if the date is past the second date, and again the third date.
 
Upvote 0
it was merely an outline, to do that you create it as a workbook open event, then set the parameters for one as between the first date and the second, then if it dosen't meet that criteria it would check your second set onwards, i wasn't pulling that fish in
 
Upvote 0
That's good, I'm starting to figure it out. I have this so far, but it keeps giving me the wrong result:

Code:
Private Sub Workbook_Open()'MsgBox "test"


If CDate("03/31/2016") > Now() Then
MsgBox "april"


'If Date < 3 / 31 / 16 Then
'MsgBox "march"
End If
End Sub

Since it is november, the april message box shouldn't appear because the current date is earlier that the date listed. Am I missing something?
 
Upvote 0
try 2015 rather than next year
 
Upvote 0
you'll get to a version of
If Now() > CDate("03/31/2015") And Now() < CDate("12/31/2016") Then
 
Upvote 0
Ok So I've updated my code, and from what I understand and searched the help functions on, my if statements seem to work (which clearly suggests that they don't), but I'm not sure what I'm doing wrong?

Code:
Private Sub Workbook_Open()'MsgBox "test"




'change 2nd date to 4/30/16 both times
If Now() > CDate("01/01/2000") And Now() < CDate("11/20/15") Then
    MsgBox "good" 'Delete this later


ElseIf Now() > CDate("11/20/15") Then
    MsgBox "Bad" 'remove later
    If Sheets("ttt").Range(A12) = "123" Then
    MsgBox "looks good for now."
    ElseIf Sheets("ttt").Range(A12) = "456" Then
    MsgBox "looks great!"
    End If






End If


End Sub

Thanks!

Andrew
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top