+ Reply to Thread
Results 1 to 8 of 8

VBA msgbox when exiting Excel workbook

  1. #1
    Forum Contributor
    Join Date
    02-22-2011
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    108

    VBA msgbox when exiting Excel workbook

    Hi,

    I have a workbook with a code when pressing the X button it prompts you it you are sure that you want to exit the program with yes and no option.

    Now i also have a user log in useform when opening the workbook and it has a cancel button so if you don't have a username or password you can then press cancel and the workbook should close however due to the msgbox prompt it then ask you if you are sure you want to exit and if the user press no the workbook stay opens and the user can then work on the workbook without entering a username and password.

    My question is can you disable the msgbox asking you if you are sure that you want to exit with the event when pressing the cancel button on the username and password prompt?

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA msgbox when exiting Excel workbook

    Hi, Hilton1982,

    you could either use a global variable to decide whether the message should be shown (false if no use, true if user had locked in), store the value to a cell and check that, use a name, a custom document property, a text file - Iīm sure I forgot one or two more ways.

    HTH,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    02-22-2011
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: VBA msgbox when exiting Excel workbook

    HaHoBe,

    Thanks for your reply I'm not sure what you mean can you explain a bit more?

    Sorry for the inconvenience.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA msgbox when exiting Excel workbook

    Hi Hilton1982,

    Why don't you upload a full working sample of the WorkBook for us to have a look at, for you?
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: VBA msgbox when exiting Excel workbook

    Hi -

    Try adding
    Please Login or Register  to view this content.
    in your form

    Regards,
    Event

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA msgbox when exiting Excel workbook

    Hi, Hilton1982,

    place a boolean Variable into a standard module right next to the top
    Please Login or Register  to view this content.
    On opening the workbook the variable is FALSE by default.

    In your lock-in-form the value is False like stated above. Only if the user has entered the workbook the variable needs to be altered. So add the line
    Please Login or Register  to view this content.
    when itīs confirmed that the user is allowed to enter the workbbok.

    Now thereīs one more change to make as we have a boolean variable but itīs not recognized by your Close-event. So you need to wrap an If-statement around that as well questioning the state of teh boolean:
    Please Login or Register  to view this content.
    @event21:
    That event isnīt set back by Excel on default - I would strongly recommend not to use if leaving a workbook or to take steps on opening Excel to reset it to True.

    Ciao,
    Holger

  7. #7
    Forum Contributor
    Join Date
    02-22-2011
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: VBA msgbox when exiting Excel workbook

    Attached is the workbook

    username jan1 and password Miles1

    So the problem is when you press cancel on the login form it will ask you if you are sure you want to exit the program and you select no you can still continue using the workboob.

    See what you can do

    Master Downtime Report V5.0.2.xlsm

  8. #8
    Forum Contributor
    Join Date
    02-22-2011
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: VBA msgbox when exiting Excel workbook

    event21

    Your little code has done the job...

    Thanks... to all for your assistance...

+ 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