Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Workbook Before Close Event (2000)

    Hi all,

    I have a tidy little bit of code that checks certain things within a sheet and prevents the user from leaving the sheet until the requirements are met. It is in a sub called from the worksheet deactivate event. I would also like to call this sub before the workbook is closed, therefore canceling the workbook close until the requirements are met. Do I call this from the workbook before close event?, and if so, how to I cancel the before close event if the sub requirements are not met? I tried putting it there and it just ran right over the sub and closed anyway.

  2. #2
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Workbook Before Close Event (2000)

    Aaaah, let's see, does "look before you leap" come to mind?

    Think if I set Cancel to true then that would do it?

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Workbook Before Close Event (2000)

    Yep! But for those who are learning about events, let's tell them where you are:
    From Excel, press <Alt> <F11>, this takes you to the VBE.
    In the top left-hand window, you have Sheet1, Sheet2, Sheet3, and ThisWorkbook.
    Double-click on ThisWorkbook and you get the code window for the Workbook.
    Press the left drop-down list arrow and select workbook.
    Press the right drop-down list arrow and select BeforeClose.
    Now if you enter MsgBox "Bye-Bye" in that event code, you'll see that message before you close.
    Don't forget to clean-up by deleting the Open event outline that was generated.
    Put Option Explicit at the top, keeps you honest and I won't debug your code unless you do.
    Have fun. You are now very dangerous! --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

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