stop save changes on exit

cocopops2001

Board Regular
Joined
Apr 18, 2011
Messages
112
hello,

i want my workbook to have a custom 'YES NO' box on exit instead of the Excel Save Changes? box. I have my exit box working fine but when i click NO excel closes down, when i click yes the box reappears and i have to click YES twice. the box is called by workbook_beforeclose

Code:
Dim ans As Integer
Sub exitbox()

ans = MsgBox("Do you want to Exit the calculation selector?", vbYesNo, "Exit")
Select Case ans
    Case vbNo
    No = True
    Exit Sub
    Case Else
End Select

    If ans = vbYes Then

    ''''saves visible properties of each sheet
    SaveStateAndHide

    ThisWorkbook.Close Saved = True
    End If

End Sub
any ideas?


EDIT: also when i click no the save changes box still appears? i have turned off application.displayalerts before the exitbox sub runs in the sub 'workbook_beforeclose'
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Can you try this:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If MsgBox("Do you want to Exit the calculation selector?", vbYesNo, "Exit") = vbNo Then
        Cancel = True
        
    Else
    
        
        SaveStateAndHide    'not sure what's in here
 
        ThisWorkbook.Save
    End If
End Sub
 
Upvote 0
works fine but for some reason i have to click YES twice when i want to exit the book. i have changed it to
Code:
workbook.close saved=true
as i do NOT want users to save any data.


EDIT: i know that by calling the close function then it will cause the msgbox to reappear just dont know what to put
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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