Consulting

Results 1 to 5 of 5

Thread: Solved: Force close

  1. #1

    Solved: Force close

    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?


    [VBA]
    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
    [/VBA]

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Try this:[VBA]
    Sub CloseNoSave()
    If Workbooks.Count = 1 Then
    Application.Quit
    Else
    ThisWorkbook.Close (False)
    End If
    End Sub
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    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.
    Last edited by Rejje; 12-01-2010 at 02:40 PM.

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    The code is NOT exactly the same as yours, look closer , above Application.Quit add:
    thisworkbook.saved=true
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Thanks a lot and I really appreciate all the support I get in this forum! Now it works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •