Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Fire a macro on Exit (VBA/Excel/2003)

    I have a macro which I want to run every time that Excel is Exited. I thought that the following code in the Personal workbook would do the trick, but it doesn't fire.

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Any recommendations?

    T.I.A.
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Fire a macro on Exit (VBA/Excel/2003)

    Create a macro named Auto_Close in a standard module in Personal.xls (not in ThisWorkbook), for example

    Sub Auto_Close()
    MsgBox "Goodbye, cruel world!", vbExclamation
    End Sub

    The name Auto_Close is obligatory, you shouldn't change it.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Fire a macro on Exit (VBA/Excel/2003)

    Thank you Hans

    It should not have been necessary for me to bother you with that. A Senior's moment? <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>
    Regards
    Don

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fire a macro on Exit (VBA/Excel/2003)

    I do think Workbook_BeforeClose should work though.

    #EDIT#

    Later: did you put the event code in the ThisWorkbook module AND did you save personal.xls?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Fire a macro on Exit (VBA/Excel/2003)

    In Excel 2002 SP3, the Workbook_BeforeClose event in the ThisWorkbook module of Personal.xls does *not* get executed. I did save Personal.xls and I restarted Excel to test it.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fire a macro on Exit (VBA/Excel/2003)

    Odd, IMO it should.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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