Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Excel - Password Protect with a criteria 1

Status
Not open for further replies.

gizmo1973

MIS
Joined
Aug 4, 2004
Messages
2,828
Location
GB
Hi,

Is it possible to protect an excel workbook with a password after a certain time frame has passed.
i.e. The workbook is created and is not protected then after 14 days a password is required to open the workbook in future?
Or if is this is not possible is there a way to get the contents of the workbook to delete after the set time frame?

Regards, Phil.

We're Coming To Get You!!!!

"Where there's blame there's DPlank"
 
Giz - if you do any VBA, just test the date in the workbook_open event and then either protect or delete as your heart desires

If theTestDate > Date then
thePass = inputbox("Please enter password to continue")
if thePass <> "the right password" then
thisworkbook.close (false)
else
end if
else
end if



Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Hi,

you can delay a macro with the OnTime function (check the help for syntax), but I'm not sure how far into the future that works, but you can give it a shot.

Another option is to make a calculation of your creation date and current date in your Workbook_Open event and have your code run as it exceeds a certain number of days. (i.e. delete the contents of the workbook)



Cheers,

Roel
 
Cheers G
sorted with that!

Regards, Phil.

We're Coming To Get You!!!!

"Where there's blame there's DPlank"
 
Code:
Private Sub Workbook_Open()
 If TestDate > Date Then
  Application.DisplayAlerts = False
       ActiveWorkbook.SaveAs Filename:=ThisWorkbook.FullName, FileFormat:= _
        xlNormal, Password:="astalavista", WriteResPassword:="test", _
        ReadOnlyRecommended:=False, CreateBackup:=False
  Application.DisplayAlerts = True
  ThisWorkbook.Save
 End If
 Sheets("Sheet2").Visible = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
 Sheets("Sheet2").Visible = xlVeryHidden
End Sub
You have to oblidge in a way the user to choose Macro Enable. So Sheet2 will always be hidden and will be unhidden only through VBA...

Fane Duru
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top