ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   password protection (https://www.excelbanter.com/excel-programming/298186-password-protection.html)

bruce forster

password protection
 
I know it is difficult to protect programs in excel but I would like to know if there is a way to put code in the Workbook start up module that would require a different password every 6 months to open. I thought I could have maybe 20 passwords, one for every 6 months, that would cover me for 10 years

Maybe an if Now is past a particular date require a password. Then the code would run the clock again until another 6 months expires

Any suggestions would be great

Please provide detailed code as i am a newbie


steveb[_4_]

password protection
 
Bruce,

This might be a little way out but try something like:

Use a workbook close event to xlVeryHidden all but one of your worksheets.

In the workbook open macro have something like:
pswrd = InputBox("Enter Password","Password")

than use If....Then or Select Case to test for
Date < yourcutoff date
pswrd = "password"
set up conditions for all your time periods

if the test is true than unhide all the worksheets. If false close the
workbook.

This code is untested but should work. Copy and paste into the
"ThisWorkbook" Module.
Keep in mind that it can be easily defeated by a skilled Excel person.

Add additonal 'Case' statements for your time periods and input your
own 'PsWord' for each.

''''''''''''''''''''''''''''''
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Long
For x = 2 To ActiveWorkbook.Worksheets.Count
Sheets(x).Visible = xlVeryHidden
' hides all but the first worksheet
Next
End Sub

Private Sub Workbook_Open()
Dim pswrd As String, PsWord As String, dte As Date

' Ask user for password
pswrd = InputBox("Enter Password", "Password")
' Today's date
dte = Date

Select Case dte
Case #1/1/2004# To #12/31/2004#
PsWord = "Word for 2004"
Case #1/1/2005# To #12/31/2005#
PsWord = "Word for 2005"
End Select

If pswrd = PsWord Then
' if password is correct, unhide the worksheets
Dim x As Long
For x = 2 To ActiveWorkbook.Worksheets.Count
Sheets(x).Visible = True
Next
' if the password is incorrect, close the workbook
Else
ThisWorkbook.Saved
ThisWorkbook.Close False
End If

End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''
--
steveb
(Remove 'NOSPAM' from email address if replying direct)


"bruce forster" wrote in message
...
I know it is difficult to protect programs in excel but I would like to

know if there is a way to put code in the Workbook start up module that
would require a different password every 6 months to open. I thought I
could have maybe 20 passwords, one for every 6 months, that would cover me
for 10 years.

Maybe an if Now is past a particular date require a password. Then the

code would run the clock again until another 6 months expires.

Any suggestions would be great.

Please provide detailed code as i am a newbie.





All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com