PDA

View Full Version : [SOLVED:] Prevent editing the file after save



YasserKhalil
06-04-2017, 04:05 AM
Hello everyone
If I have a workbook and I need it to be available for the user to enter data and edit for the first time only
After saving his data I need to prevent the editing process for the user for one hour and after the one hour to allow him edit but he has to enter a password first

Hope it is possible to do that
Thanks advanced for help

This is posted too at this link
http://www.eileenslounge.com/viewtopic.php?f=30&t=26956#p208916

mdmackillop
06-04-2017, 07:48 AM
Give this a try. I don't haven't tried closing/reopening the workbook to see how it affects the procedure.




Private Sub Workbook_AfterSave(ByVal Success As Boolean)
DoProtect
Application.OnTime Now + TimeValue("01:00:00"), "DoTime"
End Sub


Sub DoProtect()
Dim sh As Worksheet
Application.EnableEvents = False
For Each sh In ActiveWorkbook.Sheets
sh.Protect "***"
Next sh
ActiveWorkbook.Save
Application.EnableEvents = True
End Sub


Sub DoTime()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
sh.Unprotect "***"
sh.Protect "mdm"
Next sh
End Sub

YasserKhalil
06-04-2017, 10:01 AM
Thanks a lot for great help
I think it is suitable solution for my issue

I need to unprotect after the specific period of time and display input box for the user instead of protecting the sheets in the workbook