+ Reply to Thread
Results 1 to 3 of 3

Run a macro on exit

  1. #1
    More Macro Help Needed
    Guest

    Run a macro on exit

    I am looking for a way to have a file run a macro when it is being closed
    (the user either hits the X or goes File > Close). I want the macro to check
    certain cells and verify if there are values in them. If the cells are blank
    then I want an message box to come up saying that all cells are not filled in
    and the file remains open. Any help in this area is appreciated. Thanks

    Dan

  2. #2
    Tom Ogilvy
    Guest

    Re: Run a macro on exit

    Use the beforeclose event.

    See Chip Pearson's page on events
    http://www.cpearson.com/excel/events.htm

    --
    Regards,
    Tom Ogilvy

    "More Macro Help Needed" <[email protected]>
    wrote in message news:[email protected]...
    > I am looking for a way to have a file run a macro when it is being closed
    > (the user either hits the X or goes File > Close). I want the macro to

    check
    > certain cells and verify if there are values in them. If the cells are

    blank
    > then I want an message box to come up saying that all cells are not filled

    in
    > and the file remains open. Any help in this area is appreciated. Thanks
    >
    > Dan




  3. #3
    FSt1
    Guest

    RE: Run a macro on exit

    hi
    put this in the workbook's before close event

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim rng1 As Range
    Dim Rng2 As Range
    Set rng1 = Cells(1, 1)
    Set Rng2 = Cells(2, 1)
    If IsEmpty(rng1) Or IsEmpty(Rng2) Then
    MsgBox ("Required cells are empty")
    Cancel = True
    End If
    End Sub

    edit to fit your data

    Regards
    FSt1
    "More Macro Help Needed" wrote:

    > I am looking for a way to have a file run a macro when it is being closed
    > (the user either hits the X or goes File > Close). I want the macro to check
    > certain cells and verify if there are values in them. If the cells are blank
    > then I want an message box to come up saying that all cells are not filled in
    > and the file remains open. Any help in this area is appreciated. Thanks
    >
    > Dan


+ 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