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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Maybe:
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
    ActiveWorkbook.Saved = True
End Sub
 
Upvote 0
Good Morning Mumps,
I have tried this solution and have had no success. It will only work if there are two workbooks open. If this workbook that has the code is the only one open at the time of closing. it still asks me to save.
Also adding the me.saved line does not work to suppress the pop up

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
 Me.Saved = True
 
End Su
 
Last edited:
Upvote 0
I have tried it with only the workbook that has the code being open and it works properly so I don't know why it isn't working for you unless another macro is somehow interfering with it.
 
Upvote 0
Its possible that there is something else interfering with it. I will post the other code in the work book below. Take a look and see what you think.
This code clears contents from cells in the workbook when it is opened and is in sheet three

Code:
Private Sub Workbook_Open()
     'change C6 to your desired cell
     
    Range("C4:C12").Select
    Selection.ClearContents
    Range("C21:C30").Select
    Selection.ClearContents
    Range("C3").Select
    Selection.ClearContents
    
    
End Sub

This code closes the workbook from an icon on sheet three it works fine and doesn't generate any messages
code is in Module 1

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
ActiveWorkbook.Close
End Sub
 
Upvote 0
It doesn't appear that the code you posted would interfere. Perhaps you could upload a copy of your file that is giving you the problem with all the macros to a free site such as www.box.com. or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. De-sensitize any confidential data.
 
Upvote 0
Ok here is the link to download the file from Drop Box. The first tab is the main display. No information is entered here it simply uses the camera function of excel to display the charts from the information entered on tab length info. Just to look pretty lol. Click the save icon on the info page and it saves a file with a specific name and format. Close the file with the x button and this is what causes the automated save question that needs to be removed

https://www.dropbox.com/s/kze4hc72zrk9fvk/Cookie Length Chart Blank REV 1A.xlsm?dl=0
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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