Stop Excel Asking to Save

ChaosPup

New Member
Joined
Sep 27, 2021
Messages
48
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I run a very basic 'Save and Close' macro button in one of my spreadsheets (Excel 2016) -

VBA Code:
Sub Save_and_Close()

    Application.Quit
    ThisWorkbook.Save
    
End Sub

Problem is, when the button is pressed the sheet saves correctly but I still get this message -

1652266877486.png


Is there any way to prevent this?

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It doesn't seem to make much sense to quit the application (close Excel), and then try to save the file (the file is already closed at that point, so there would be nothing to save!).
I think you need to switch the order of those two commands. And then you wouldn't get that warning, as the file would already just have been saved.
 
Upvote 0
Solution
Hi
Try
Ap
VBA Code:
Application.DisplayAlerts = False
And
VBA Code:
Application.DisplayAlerts = True

May be some thing like
VBA Code:
Sub Save_and_Close()
    Application.DisplayAlerts = False
    ThisWorkbook.Save
    Application.DisplayAlerts = True
    Application.Quit
End Sub
Not tested
 
Upvote 0
Hi
Try
Ap
VBA Code:
Application.DisplayAlerts = False
And
VBA Code:
Application.DisplayAlerts = True
That will hide that message, but doesn't get around the issue I mentioned.
There is nothing to save if everything is closed!

Sometimes the messages are telling you something important (i.e. there is an issue with your code), and you need to pay attention to what it is telling you and why it is happening.
 
Upvote 0
Thanks everyone,

Swapping the commands over was absolutely correct, can't believe I missed that. That change by itself didn't fix the issue though, I still had to add the the display alerts line.

Sorted now, thanks!
 
Upvote 0
Thanks everyone,

Swapping the commands over was absolutely correct, can't believe I missed that. That change by itself didn't fix the issue though, I still had to add the the display alerts line.

Sorted now, thanks!
I am guessing then that you must have multiple workbooks open, as if it was just the one with the macros, then Save command who be sufficient, and it wouldn't prompt you to save it again.
Anyway, glad you got it sorted out.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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