+ Reply to Thread
Results 1 to 6 of 6

execute code on userform close buton

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    execute code on userform close buton

    I came across an interesting issue:
    I have a userform with various comboboxes and text boxes and each of these boxes has this simple code:
    Please Login or Register  to view this content.
    (btw ChangesDetected is publicy declared as a boolean)
    The code below executes once the userform is closed and if ChangesDetected = True then the code prompts the user with a message box.
    Please Login or Register  to view this content.
    Now comes the interesting part; if i close the userform via a custom close button that uses "unloadme" the code works fine, but if i close the userform via the the top right "X" the code will process the boolean variable. How do i know that the code is ignoring it? That;s because if i put a random message box at the beginning then if i click on the "X" the msgbox will show. For some reason the "X" is ignoring the boolean.
    I would really appreciate any help on this.

    Thanks in advance!

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: execute code on userform close buton

    Hi kosherboy

    Disable the X button. Here's some Code from our own Leith Ross to do so.

    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: execute code on userform close buton

    Hi jaslake,
    That is some cool stuff from Leith Ross!
    Thanks for sharing
    I have one issue though, when the the user clicks anywhere on the userform (not existing objects) and this code is executed:
    Please Login or Register  to view this content.
    it then clears the boolean that was created and then if i click on the "close" button that i created the code again won't execute
    The code will execute if i avoid clicking the actual userform but then it will be unsafe.
    I tried disabling the userform but that was catastrophic as it disabled all the objects as well
    Any ideas?
    Thanks!

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: execute code on userform close buton

    Hi kosherboy

    I have no clue. I'll be glad to look at it in a Sample File...

  5. #5
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Waterbury, CT
    MS-Off Ver
    Office 365
    Posts
    1,175

    Re: execute code on userform close buton

    I forgot to change something in my code, all good now!
    The information you provided is very helpful, thanks

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: execute code on userform close buton

    You're welcome...glad I could help. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. code to execute a keyboard shortcut or to execute a toolbar button
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2015, 12:16 PM
  2. [SOLVED] Must open and close UserForm twice for the other codes in the "Open..." Macro to execute
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-10-2013, 09:28 AM
  3. Code for save and close Button on Userform
    By cjames2012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2013, 12:49 AM
  4. Code a Command Button on UserForm not to close upon click - Excel VBA
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-14-2012, 02:20 PM
  5. Commandbutton in userform to execute code based on a previous commandbutton choice?
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2012, 03:28 PM
  6. Execute code from auto generated buttons in a userform
    By Tellus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-27-2008, 09:07 AM
  7. Dissable Close button on Userform or Assign Code
    By RobynC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2007, 10:07 AM

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