PDA

View Full Version : Solved: Force close



Rejje
12-01-2010, 06:42 AM
Hi! How can I alter this macro so that Excel will not ask for saving YES/NO/CANCEL?

This should be a force close code for the workbook. In case it's the last open workbook; force close application. Any ideas someone?



Sub CloseNoSave()

Dim answer As VbMsgBoxResult
answer = MsgBox("Do you really want to quit without saving?", vbYesNo)

If answer = vbYes Then

If Workbooks.Count = 1 Then
Application.Quit
Else
ThisWorkbook.Close (False)
End If

End If

End Sub

Simon Lloyd
12-01-2010, 12:41 PM
Try this:
Sub CloseNoSave()
If Workbooks.Count = 1 Then
Application.Quit
Else
ThisWorkbook.Close (False)
End If
End Sub

Rejje
12-01-2010, 02:25 PM
Hmm...

Code is exactly the same as mine (think I got it from you once). And problem still remains; Excel will still ask "Save? YES/NO/CANCEL" in case one has made any changes.

Simon Lloyd
12-02-2010, 05:46 AM
The code is NOT exactly the same as yours, look closer :), above Application.Quit add:
thisworkbook.saved=true

Rejje
12-02-2010, 12:46 PM
Thanks a lot and I really appreciate all the support I get in this forum! Now it works!