View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
quartz[_2_] quartz[_2_] is offline
external usenet poster
 
Posts: 441
Default 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