+ Reply to Thread
Results 1 to 4 of 4

BeforeClose Macro

  1. #1
    Registered User
    Join Date
    11-09-2006
    Posts
    2

    BeforeClose Macro

    Hi,

    Have a workbook saved in excel 2002 with the following macro:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call Macro1
    End Sub

    And macro1 is another macro required to run befor e I close the book. But unfortunately, this doesnt run when I prees either the X at the top right hand corner or >File>Close

    Any ideas? (I am not much of a VBA wizard!!!)

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    when does it run? if it doesn't run on either of the actions, you might not have the code in the right spot
    here's is a site the explains where the workbook module is

    http://www.contextures.com/xlvba01.html
    Last edited by davesexcel; 11-09-2006 at 07:35 AM.

  3. #3
    Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    267
    Have you got the sub workbook before close in the 'This Workbook' module? Rather than a standard module. Macro 1 however should be in a standard module.

    There is nothing wrong with the following code

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call Macro1
    End Sub


    Unless there is something in macro1 itself causing this?

    Hope it helps
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  4. #4
    Registered User
    Join Date
    11-09-2006
    Posts
    2

    Bingo!!!

    Thanks guys you were both right, I had not placed the code in the "This Workbook" section. I was unaware that this had to be done, at least I will know in future

    Thanks for a very quick response!

    Kev

+ 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