ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel remaining open on workbook exit (https://www.excelbanter.com/excel-programming/396597-excel-remaining-open-workbook-exit.html)

[email protected]

Excel remaining open on workbook exit
 
Hi,

I want my workbook to not prompt the user to save it on exit. This is
because the form is showing information from files that the user
selects and when they close the workshhet I want it to remain in the
state it was in when the opened it first.

So, I use the following code to block the "Save" request -

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

The problem is that if I press the exit botton fo rthe excel
application, the workbook closes but excel remains open. How might I
fix this?

Thanks,

Aine.


Halim

Excel remaining open on workbook exit
 
Hi,
Fixing your code maybe help:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.Quit 'this is the point.....
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

--
Regards,

Halim



" wrote:

Hi,

I want my workbook to not prompt the user to save it on exit. This is
because the form is showing information from files that the user
selects and when they close the workshhet I want it to remain in the
state it was in when the opened it first.

So, I use the following code to block the "Save" request -

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

The problem is that if I press the exit botton fo rthe excel
application, the workbook closes but excel remains open. How might I
fix this?

Thanks,

Aine.



papou[_2_]

Excel remaining open on workbook exit
 
Hello Aine
IMHO, you can't because your code is at workbook level.
You will either have to always remember and close your workbook or use a
class module.
BTW, I would amend your code with:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Saved = True
Me.Close
End Sub

HTH
Cordially
Pascal

a écrit dans le message de news:
...
Hi,

I want my workbook to not prompt the user to save it on exit. This is
because the form is showing information from files that the user
selects and when they close the workshhet I want it to remain in the
state it was in when the opened it first.

So, I use the following code to block the "Save" request -

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

The problem is that if I press the exit botton fo rthe excel
application, the workbook closes but excel remains open. How might I
fix this?

Thanks,

Aine.




papou[_2_]

Excel remaining open on workbook exit
 
Please amend previous amendment suggestion:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Saved = True
Me.Close
Application.Quit
End Sub

Cordially
Pascal
a écrit dans le message de news:
...
Hi,

I want my workbook to not prompt the user to save it on exit. This is
because the form is showing information from files that the user
selects and when they close the workshhet I want it to remain in the
state it was in when the opened it first.

So, I use the following code to block the "Save" request -

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

The problem is that if I press the exit botton fo rthe excel
application, the workbook closes but excel remains open. How might I
fix this?

Thanks,

Aine.





All times are GMT +1. The time now is 04:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com