Can I make this macro close the document without saving?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a macro that checks if a document should be closed or not,

it works great, but I get the Do you want to Save document request after it runs as you would expect, however theres never a time this document needs saving so could this macro just close the document for me without saving?

please help if you can

Tony

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
If Sheets("Welcome").Range("F1") <> "Submitted" Then
promptit = MsgBox("You have not submitted any data, closing this document will mean all Changes will be lost. Do you want to close document?", vbYesNo, "DATA NOT SENT")
If promptit = vbNo Then
    Cancel = True
    Exit Sub
End If
End If
Resume Next

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
nicked from elsewhere

Code:
Activeworkbook.Saved = True

before closing
 
Upvote 0
Oh, that's easy, i'mm sure I've used it loads of times before just didn't realise that's what it did lol.

Thanks very much Mole.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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