Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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?


--
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Quiting Excel program?


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!


Code:
--------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)

If Not Me.Saved Then
Msg = "Do you want to save the changes you made to "
Msg = Msg & Me.Name & "?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
End If

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=559216

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default 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

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Quiting Excel program?


Thanks for the advice Edwin

Regards
Theun

--
T.c.Goosen197
-----------------------------------------------------------------------
T.c.Goosen1977's Profile: http://www.excelforum.com/member.php...fo&userid=3589
View this thread: http://www.excelforum.com/showthread.php?threadid=55921

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to unload the loaded XLL file in Excel? Hi all, I amdebugging XLL link library using Visual C++. Everytime I rebuild the XLL, Ihave to close the whole Excel program and relaunch the Excel program again,and then load in the newly gene LunaMoon Excel Discussion (Misc queries) 0 July 28th 08 11:03 PM
Help with quiting a workbook Tempy Excel Programming 1 August 31st 05 12:41 PM
Excel crashes after quiting Niranjan[_2_] Excel Programming 0 June 8th 05 10:06 AM
Quiting Gracefully! Kevin Excel Programming 5 September 9th 04 07:49 PM
Quiting Excel Michael Wise Excel Programming 4 March 4th 04 03:36 PM


All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"