ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cancel an application exit from VBA? (https://www.excelbanter.com/excel-programming/344049-cancel-application-exit-vba.html)

helmekki[_98_]

Cancel an application exit from VBA?
 

Hi there

How do I cancel an application exit from VBA?


--
helmekki


------------------------------------------------------------------------
helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939
View this thread: http://www.excelforum.com/showthread...hreadid=479941


quartz[_2_]

Cancel an application exit from VBA?
 
Helmekki,

As long as a file is open in Excel, you can put the following code in the
"ThisWorkbook" module and it worked for me - it keeps both the file and the
Application from closing:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True: Call YourOtherCodeHere
End Sub

Note: You will need to call some other code or add some code to the above or
you and/or your user will never be able to exit. To work around that, check
out: Application.EnableEvents = False/True.

HTH/

"helmekki" wrote:


Hi there

How do I cancel an application exit from VBA?


--
helmekki


------------------------------------------------------------------------
helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939
View this thread: http://www.excelforum.com/showthread...hreadid=479941



Chip Pearson

Cancel an application exit from VBA?
 
If the event declaration has a parameter named 'Cancel', set that
variable to True. Otherwise you can't cancel individual events.
However, you can events from being triggered at all with

Application.EnableEvents = False

Be sure to set it back to true at the appropriate place in code.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"helmekki"
wrote in
message
...

Hi there

How do I cancel an application exit from VBA?


--
helmekki


------------------------------------------------------------------------
helmekki's Profile:
http://www.excelforum.com/member.php...fo&userid=6939
View this thread:
http://www.excelforum.com/showthread...hreadid=479941




helmekki[_99_]

Cancel an application exit from VBA?
 

Thank u

It worked fine


--
helmekki


------------------------------------------------------------------------
helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939
View this thread: http://www.excelforum.com/showthread...hreadid=479941



All times are GMT +1. The time now is 07:47 AM.

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