View Single Post
 
Old 09-29-2021, 12:15 PM
Purfleet Purfleet is offline Windows 10 Office 2019
Expert
 
Join Date: Jun 2020
Location: Essex
Posts: 345
Purfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to behold
Default

as logit has said the beforeClose thisworkbook is ideal for what you want, but you dont need to ask the user to do anything.

If you open the this workbook Module in the VBA editor you will see drop downs at the top the one on the left (general) can be changed to Workbook (it acts when the workbook does something).

The one on the right is the thing that happens - there is quite a few, but some are really obvious like BeforeClose.

Select BeforeClose and a automated Private Sub will open called Workbook_BeforeClose

In between the 2 lines put in anythng you want to happen before the workbook is closed, for example

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

    ActiveWorkbook.Save
    Worksheets("Form").Protect
    
End Sub
Be careful with the Activeworkbook.save though because if the user does something stupid like delete all the data and then they close it because they panic it will save with all the data lost
Reply With Quote