stop Pop Up do you want to Save?

phillipclark

Board Regular
Joined
Sep 10, 2013
Messages
65
Good afternoon All,
I am using the below code when the close button is used to ask the user a series of questions based on yes or no answers. This works fine and I have no issues. The problem i have is that excel will have the pop up asking the user to save the file. I am already using a macro and custom file name so i need to disable all of these request. What do i need to add to my code below in order to prevent this request from excel.

Thank You in advance for all your help.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("Have you saved the data?", vbYesNo) = vbYes Then Cancel = False
If MsgBox("Would you like to cancel close?", vbYesNo) = vbYes Then Cancel = True
End Sub
 
I tried this as well in a new work book with my code from post #3 and it works fine. I will delete the other work book create a new one and see what happens. When I return next week will post the results to here.

Thank you all
Until then
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Good Morning All,
I created the new work book and started having the same problem with the pop asking to save. I decided to delete the graphs that are in the work book and then everything was ok the code started working again. Add the graphs back into the work book the code for closing works but the pop ups for saving return. Has anyone else experienced this or have a solution.

Thank You
 
Upvote 0
Good Morning all,
If the code works without the graphs and doesn't when the graphs are present does this mean there is some kind of screen updating that is taking place at the end of the code that creates the request to save again. Can this be turned off? Just trying to drive to root cause so that we can post a true solution so that everyone benefits. I know I cant be the only one with this problem though considering the cosmos and how it works maybe I am lol.
 
Upvote 0
Good Afternoon All,
In the end the issue was apparently Excel itself. I had shut down my computer for the weekend came back restarted and everything in the workbooks started working and has continued to do so.
Below i will post the code that is now working along with the graphs. Something must have become corrupted with Excel and righted itself after being rebooted.

Thank You everyone for all your help with this matter in the end i came up with better code and understanding of VBA which is what we are all after in the first place :)

Code:
Sub SaveIt()
Dim dt As String, wbNam As String
wbNam = "Cookie Length Chart_"
dt = Format(CStr(Now), "yyyy_dd_mm_hh_mm AMPM")
ActiveWorkbook.SaveAs Filename:=wbNam & dt, FileFormat:=52
Application.DisplayAlerts = False
Application.Quit


End Sub
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("Are you sure you want to Close the WorkBook?" & vbNewLine & "Tem certeza de que deseja fechar este Worrkbook?", vbYesNo + vbQuestion) = vbNo Then Cancel = True
Application.DisplayAlerts = False
Application.Quit


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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