Disable Save Prompt on Close - Not Working

mikeinvirginia

New Member
Joined
Nov 18, 2021
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hi all,

I love this site. I have seen questions on how to close a workbook with no save prompt. I have a tried the below set of macros. I still receive the prompt. I included all my macros. Maybe another macro is interfering. The first two macros work as intended. Clear range. The next set, I would like to disable the prompt to save the workbook. I still receive the prompt to save. I placed the macros in this workbook.


VBA Code:
Private Sub Workbook_Open()
Application.EnableEvents = False
Worksheets("Calculator").Range("C4:C5").Value = ""
Application.EnableEvents = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Calculator").Range("C4:C5").Value = ""
End Sub

Private Sub Auto_Close()
        ThisWorkbook.Saved = True
Private End Sub

Private Sub CloseBook()
Application.DisplayAlerts = False
ThisWorkbook.Close
Application.DisplayAlerts = True
Private End Sub

Private Sub CloseBook2()
ThisWorkbook.Close savechanges:=False
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,769
Office Version
  1. 2013
Platform
  1. Windows
Hi & welcome to MrExcel.

This should work as required. Be sure that this code is pasted in the ThisWorkbook module.
Note that the Me.Saved=True line should always be the last line just before the End Sub statement.

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Calculator").Range("C4:C5").Value = ""
'
' some other code, or not
'
Me.Saved = True
End Sub
 
Solution

mikeinvirginia

New Member
Joined
Nov 18, 2021
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Thanks! Solved. I made sure me.saved = true was the last line.

VBA Code:
Private Sub Workbook_Open()
Application.EnableEvents = False
Worksheets("Calculator").Range("C4:C5").Value = ""
Application.EnableEvents = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Calculator").Range("C4:C5").Value = ""
Me.Saved = True
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,255
Messages
5,836,271
Members
430,414
Latest member
ayla

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