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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

stuartford

Active Member
Joined
Nov 28, 2002
Messages
419
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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Put this in the ThisWorkbook module:

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

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
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:
 

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
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!
 

Forum statistics

Threads
1,144,615
Messages
5,725,321
Members
422,613
Latest member
salim9696

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
Top