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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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


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



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

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
How to get userform Cancel button to invoke Exit Sub in calling macro? Craig Remillard New Users to Excel 1 November 19th 09 03:55 AM
Cancel/Exit Sub Howard Excel Discussion (Misc queries) 3 December 16th 08 09:53 PM
Exit Code Upon Cancel On Type 8 Input Box FARAZ QURESHI Excel Discussion (Misc queries) 2 March 31st 08 09:22 AM
InputBox / VBA question ok = print, cancel = exit todd78 Excel Worksheet Functions 4 August 9th 07 04:42 PM
Cancel Exit on duplicate Garry Jones Excel Programming 2 November 3rd 03 11:21 PM


All times are GMT +1. The time now is 08:25 PM.

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

About Us

"It's about Microsoft Excel"