Close a workbook immediately (no save prompt etc.)

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
Firstly, thanks for reading.

I want to have a macro so that if the user of my spreadsheet clicks close, or alt f4 or the cross in the corner etc. that it does not prompt them to save; rather it just immediately closes.

Edit: just to clarify I don't want it to save automatically or anything, just close without saving any changes (I plan on making the file read only anyway so they can't make any changes at all!)

Thanks.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
this may be no soulution but here goes any way


couldnt you just set the file itself to open as read only then its not possible to save it over the original

any help?

Stu
 
Upvote 0
Put this in the ThisWorkbook module:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean) 
    ThisWorkbook.Saved = True 
End Sub
 
Upvote 0
Hello LostCause,
You can put this in the ThisWorkbook module to achieve that.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub

Just make sure all your users know that it must get saved manually if they ever want to
save any changes. :wink:
 
Upvote 0
Thanks guys

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean) 
ThisWorkbook.Saved = True 
End Sub

Worked a treat. Stu - sorry I phrased my question poorly!
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top