+ Reply to Thread
Results 1 to 8 of 8

Activate Cancel Button on a Modeless Userform

  1. #1
    Registered User
    Join Date
    03-08-2012
    Location
    Notts
    MS-Off Ver
    Excel 2010
    Posts
    71

    Activate Cancel Button on a Modeless Userform

    Good Afternoon,

    This may be a stupid question that I already know the answer to, but;
    Is there any way to make a Cancel button on a userform exit the macro and hide the userform?

    I know various code to do this when the userform is not modeless:

    Please Login or Register  to view this content.
    But is there a cheeky way that I don't know about to make the cancel button operate when the form is loaded as modeless??

  2. #2
    Registered User
    Join Date
    08-22-2012
    Location
    Bhubaneswar
    MS-Off Ver
    Excel 2003,2007
    Posts
    95

    Re: Activate Cancel Button on a Modeless Userform

    Hello Mr mtt23

    I can't understand your question but what ever it may be here is a code for you

    Please Login or Register  to view this content.
    With Regards

    Patnaik

  3. #3
    Registered User
    Join Date
    03-08-2012
    Location
    Notts
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Activate Cancel Button on a Modeless Userform

    I have set a userform to modeless because I am using it as a status bar while the macro runs and I want it to stay up on the screen, but in modeless, the usual code that I would use for the cancel button will not work.

    I am asking, is there a way to make canel work when form is modeless. Or not?

  4. #4
    Registered User
    Join Date
    03-08-2012
    Location
    Notts
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Activate Cancel Button on a Modeless Userform

    No wizards around that can clarify this for me?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Activate Cancel Button on a Modeless Userform

    Something like this perhaps.

    Userform simply displays the time until user cancels

    code module
    Please Login or Register  to view this content.
    Userform with command button and label
    Please Login or Register  to view this content.
    Note: Avoid using END in your code as it free all memory used by VBA, including private and publically scoped variables.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Activate Cancel Button on a Modeless Userform

    you would normally do this using a public variable that is set by the cancel button and checked periodically by your macro but unless your macro yields control occasionally (using doevents for instance) it will be hard to get the form to do anything.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Registered User
    Join Date
    03-08-2012
    Location
    Notts
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Activate Cancel Button on a Modeless Userform

    Thanks guys!

    Joseph, I think I will have to do something along the lines of that, as I already have occasional code throughout the main macro which updates my progress bar within the same userform...

  8. #8
    Registered User
    Join Date
    05-13-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2010/13
    Posts
    1

    Re: Activate Cancel Button on a Modeless Userform

    Thanks Andy, I found this extremely useful for a macro I am building. Cheers

+ 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