View Single Post
 
Old 09-30-2021, 08:07 AM
p45cal's Avatar
p45cal p45cal is offline Windows 10 Office 2019
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

Quote:
Originally Posted by Purfleet View Post
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

    ActiveWorkbook.Save
    Worksheets("Form").Protect
    
 End Sub
If you save before closing, then protect the sheet, I suspect the workbook will ask again if it should be saved to which you have to answer Yes in order for the sheet to be protected in the saved file.
Personally, as your codicil suggests being wary of .Save, I'd miss it out altogether in that event handler and only include the .Protect line. That way, whether the file is saved or not (with/without erroneous changes made by the user) is left for the user to decide, which is the usual behaviour on closing a workbook.
Reply With Quote