+ Reply to Thread
Results 1 to 4 of 4

Quiting Excel program?

  1. #1
    Registered User
    Join Date
    06-29-2006
    Posts
    60

    Quiting Excel program?

    Im using the following code to quite excel:

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Application.Quit
    ActiveWorkbook.Close
    End Sub

    A standard saving message pops up when i click the "x" on the userform, if I click “yes” it saves the file and quits excel = 100% , if I click “no” it does not save the file but it quits excel = 100%, but when I click the cancel button or the "x" it does not unload the standard excel saving message and resume the userform...it goes into debug mode?

  2. #2
    Registered User
    Join Date
    06-13-2006
    Posts
    76

    Quit Excel

    Hi Theuns,

    Try this piece of VBA code. In the VB Editor you will find the folder "Microsoft Excel Objects". Put this code in the object "ThisWorkbook" and it should work fine!

    Please Login or Register  to view this content.

  3. #3
    Edwin Tam
    Guest

    RE: Quiting Excel program?

    The procedure has been "blocked" during the file save process.
    To solve this problem, you need to do one more step, which is, after Excel
    prompts to save all unsaved files, use macro to force Excel to close all
    workbooks no matter what. Then quit application.

    The code below may look longer than necessary. But it'll ensure a more
    secured result.

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Dim a As Workbook
    For Each a In Workbooks
    If a.Name <> ThisWorkbook.Name Then a.Close
    Next
    For Each a In Workbooks
    If a.Name <> ThisWorkbook.Name Then a.Close False
    Next
    ThisWorkbook.Saved = True
    Application.Quit
    End Sub

    Regards,
    Edwin Tam
    [email protected]
    http://www.vonixx.com



    "T.c.Goosen1977" wrote:

    >
    > Im using the following code to quite excel:
    >
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
    > Integer)
    > Application.Quit
    > ActiveWorkbook.Close
    > End Sub
    >
    > A standard saving message pops up when i click the "x" on the userform,
    > if I click “yes” it saves the file and quits excel = 100% , if I click
    > “no” it does not save the file but it quits excel = 100%, but when I
    > click the cancel button or the "x" it does not unload the standard
    > excel saving message and resume the userform...it goes into debug mode?
    >
    >
    > --
    > T.c.Goosen1977
    > ------------------------------------------------------------------------
    > T.c.Goosen1977's Profile: http://www.excelforum.com/member.php...o&userid=35895
    > View this thread: http://www.excelforum.com/showthread...hreadid=559216
    >
    >


  4. #4
    Registered User
    Join Date
    06-29-2006
    Posts
    60
    Thanks for the advice Edwin

    Regards
    Theuns

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1