Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 4 of 4

Thread: Workbook_beforeclose event

  1. #1
    Join Date
    26th October 2003
    Location
    Perth, Western Australia
    Posts
    103

    Workbook_beforeclose event

    I am having a little trouble with the code below. If cancel is selected it doesn't make the menu sheet visible again. What am I doing wrong?

    Thanks,

    Daniel

    VB:
    Private Sub workbook_beforeclose(cancel As Boolean) 
         
         'If cancel button is selected then show the "menu" sheet
         'This bit doesn't do what I expected.
        If cancel = True Then 
            Worksheets("menu").Visible = True 
            Worksheets("1").Visible = False 
             
        End If 
         'This bit works
        Worksheets("1").Visible = True 
        Worksheets("menu").Visible = False 
    End Sub 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    22nd January 2004
    Location
    Colorado Springs
    Posts
    3,748

    Re: Workbook_beforeclose event

    DMariotti,


    The "cancel" variable just tells excel whether or not to actually close the workbook. This is there just in case you have some properties that need setting and if during processing you need to acutally prevent the workbook from closing you would set " Cancel = TRUE "

    When the workbook close event fires it is always "FALSE" hence you never get inside your if statment.
    Regards,
    Barry

    My Favorite New Thing:
    Dynamic Named Ranges



    The alternative for
    "Press Any Key To Continue."

    and we all have one we'd like to use it on


    1. Cross Posting Etiquette
    2. Are You Here To Learn: What Have You Tried?

  3. #3
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,697

    Re: Workbook_beforeclose event

    Hi Daniel

    You could simply use the code below
    VB:
    Private Sub workbook_beforeclose(cancel As Boolean) 
        Worksheets("menu").Visible = cancel 
        Worksheets("1").Visible = Not cancel 
    End Sub 
    
    

  4. #4
    Join Date
    26th October 2003
    Location
    Perth, Western Australia
    Posts
    103

    Re: Workbook_beforeclose event

    Thanks Barry and Dave for the help

    Daniel

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. click event vs selection change event
    By halster1 in forum EXCEL HELP
    Replies: 4
    Last Post: July 10th, 2010, 10:53
  2. Workbook_beforeclose Fires Twice
    By sparrowUK in forum EXCEL HELP
    Replies: 6
    Last Post: June 29th, 2007, 23:43
  3. Workbook_BeforeClose doesn't work
    By dales4life in forum EXCEL HELP
    Replies: 8
    Last Post: September 28th, 2005, 04:37
  4. Errors with Workbook_BeforeClose()
    By CameronY in forum EXCEL HELP
    Replies: 1
    Last Post: April 12th, 2005, 09:03

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
  •  
porno