+ Reply to Thread
Results 1 to 4 of 4

Cancel an application exit from VBA?

  1. #1
    Forum Contributor
    Join Date
    03-09-2004
    Posts
    140

    Cancel an application exit from VBA?

    Hi there

    How do I cancel an application exit from VBA?
    Yours
    hesham Almakki
    http://www.almakki.com.ly/

  2. #2
    quartz
    Guest

    RE: 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. #3
    Chip Pearson
    Guest

    Re: 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"
    <[email protected]> wrote in
    message
    news:[email protected]...
    >
    > 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. #4
    Forum Contributor
    Join Date
    03-09-2004
    Posts
    140

    Thumbs up

    Thank u

    It worked fine
    Last edited by helmekki; 10-27-2005 at 10:39 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1