+ Reply to Thread
Results 1 to 4 of 4

How to ensure a VBA sub is run before closing a workbook

  1. #1
    Jacqui
    Guest

    How to ensure a VBA sub is run before closing a workbook

    What syntax would I use to make sure specific subs are run before Excel
    closes the active workbook. These subs are error checks and I need VBA to
    vet the data and alert the user there are errors before the workbook is
    closed. Is it the Workbook_Before Close event?. I tried adding the syntax
    below but it didn't trigger the subs. Also would an On Save type event (if
    there is one) be a better alternative. Can anyone recommend a solution with
    some code please.
    Many thanks
    Jacqui

    Private Sub Workbook_BeforeClose()

    Qualifiers_Check
    Disable_Check

    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: How to ensure a VBA sub is run before closing a workbook

    BTW, syntax of BeforeClose is

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Jacqui" <[email protected]> wrote in message
    news:[email protected]...
    > What syntax would I use to make sure specific subs are run before Excel
    > closes the active workbook. These subs are error checks and I need VBA to
    > vet the data and alert the user there are errors before the workbook is
    > closed. Is it the Workbook_Before Close event?. I tried adding the

    syntax
    > below but it didn't trigger the subs. Also would an On Save type event

    (if
    > there is one) be a better alternative. Can anyone recommend a solution

    with
    > some code please.
    > Many thanks
    > Jacqui
    >
    > Private Sub Workbook_BeforeClose()
    >
    > Qualifiers_Check
    > Disable_Check
    >
    > End Sub




  3. #3
    Bob Phillips
    Guest

    Re: How to ensure a VBA sub is run before closing a workbook

    The event is correct. Did you put the code in the ThisWorkbook code module.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Jacqui" <[email protected]> wrote in message
    news:[email protected]...
    > What syntax would I use to make sure specific subs are run before Excel
    > closes the active workbook. These subs are error checks and I need VBA to
    > vet the data and alert the user there are errors before the workbook is
    > closed. Is it the Workbook_Before Close event?. I tried adding the

    syntax
    > below but it didn't trigger the subs. Also would an On Save type event

    (if
    > there is one) be a better alternative. Can anyone recommend a solution

    with
    > some code please.
    > Many thanks
    > Jacqui
    >
    > Private Sub Workbook_BeforeClose()
    >
    > Qualifiers_Check
    > Disable_Check
    >
    > End Sub




  4. #4
    Tushar Mehta
    Guest

    Re: How to ensure a VBA sub is run before closing a workbook

    The BeforeClose procedure declaration is incorrect. The best way to
    get these relatively trivial things correct is to let XL do the work.

    The code goes in the Workbook's code module. The easiest way to figure
    out where is to right-click the workbook icon to the left of the
    'File' in the menu bar and select View Code.

    In the XL VBE towards the middle top there is a drop down that will
    read (General). Use it to select Workbook. In the adjacent dropdown,
    select BeforeClose. You will now have the correct syntax for the
    BeforeClose procedure.

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,
    [email protected] says...
    > What syntax would I use to make sure specific subs are run before Excel
    > closes the active workbook. These subs are error checks and I need VBA to
    > vet the data and alert the user there are errors before the workbook is
    > closed. Is it the Workbook_Before Close event?. I tried adding the syntax
    > below but it didn't trigger the subs. Also would an On Save type event (if
    > there is one) be a better alternative. Can anyone recommend a solution with
    > some code please.
    > Many thanks
    > Jacqui
    >
    > Private Sub Workbook_BeforeClose()
    >
    > Qualifiers_Check
    > Disable_Check
    >
    > End Sub
    >


+ 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