PDA

View Full Version : Solved: when closing file and users click on NO (do you want to save...)...ask one more time



PaSha
11-26-2007, 03:43 AM
hy guys...

this question is maybe a little bit tuff...

i was thinking is it posible to make a code in the workbook, that when the user closes the workbook and there comes that pop up box "Do you want to save changes" ... and when he clicks no that there should come one more question : Are you sure??? ...

hope this can be done...

TonyJollans
11-26-2007, 04:08 AM
As far as I know there is no event that occurs after an aborted save so the answer is no - at least not in the normal course of events.

You could trap the close request and ask up front *before* Excel does - or you could even save a copy just in case - so that if they said no to your prompt they would get a second chance when Excel prompted them.

Bob Phillips
11-26-2007, 04:11 AM
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ans As Long
Dim ansAgain As Long
Application.EnableEvents = False
If Not ThisWorkbook.Saved Then
ans = MsgBox("Do you want to save the changes you made to '" & ThisWorkbook.Name & "'", _
vbYesNoCancel + vbExclamation)
If ans = vbYes Then
ThisWorkbook.Save
ElseIf ans = vbNo Then
ansAgain = MsgBox("Are you sure?", vbYesNo + vbQuestion)
If ansAgain = vbNo Then
ThisWorkbook.Save
End If
Else
Cancel = True
End If
End If
Application.EnableEvents = True
End Sub


This is workbook event code.
To input this code, right click on the Excel icon on the worksheet
(or next to the File menu if you maximise your workbooks),
select View Code from the menu, and paste the code

PaSha
12-06-2007, 09:21 AM
Thanks xld you're the best...

it works perfect ...

this is what i was looking for... i just had now time to see if it works, and it super...

so thanks again...