Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Skip workbookbefore_close sub: how

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    162
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have a file with a nice workbook_beforeclose sub in it. In this sub some cells are checked for their contents and if the contents is not correct the sheet will not close.

    However, I want to insert a button with which people can exit the sheet anyways.
    Now I have a activeworkbook.close statement behind this button but then ofcourse the workbookbefore_close sub stops the file from being closed.

    Can I somehow program the button to skip the workbook_beforeclose sub?

    thnks, I hope someone can help me.

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi,

    One way you could do it is to declare a variable in a standard module as Public e.g.

    Public OKToClose As Boolean

    Then in your command button code put this:-

    OKToClose = True

    Then in your Workbook_Close subroutine put this:-

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If OKToClose = True Then Exit Sub

    'Rest of your code
    End Sub


    HTH,
    Dan

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    162
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Right!

    This works. I thank you a lot!

    Cheers.

    [ This Message was edited by: Dinictus on 2002-04-24 06:38 ]

  4. #4
    New Member
    Join Date
    Apr 2002
    Location
    Lawrence, KS
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    you can also turn off events with
    application.enableevents = false
    don't foget to turn them back on.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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