Excel sheet not closing after Quiting application

  • Hi all
    I have an excel VBA application where I disable the X button at application launch, when quitting the application the last sheet remains open and I can't close it! The code I use is;


    Public DisableX As Boolean


    Sub Workbook_BeforeClose(Cancel As Boolean)
    'Close workbook from main form only!

    If DisableX = False Then Cancel = True

    End Sub


    Any thoughts will be appreciated.

  • Hi,


    Off the top of my head I am wondering if you are setting DisableX to False in your UserForms Close Workbook Subroutine ?


    Regards,


    Tom Rowe.

  • You should declare the Public Boolean variable DisableX on a Standard Module.
    And where do you change the value of DisableX? Is it ever set to be True? Otherwise it will remain False and you cannot close the workbook.

    Regards.
    sktneer

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!