+ Reply to Thread
Results 1 to 5 of 5

Autoclose form doesn't always close when it should?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Unhappy Autoclose form doesn't always close when it should?

    I have tried to create a popup form that will auto close after a specified number of seconds and also allow early closure by Escape key or by user clicking the form.

    Below is my code - poor as it is. I don't understand why but sometimes this code gets stuck in the For...Next loop even when the mblnExitMe value is True. There must be a basic fundamental that I am not getting but I'm not sure what it could be.


    Please Login or Register  to view this content.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Autoclose form doesn't always close when it should?

    I don't know the reason it gets stuck, but I would suggest a better alternative to a For-Next loop and Sleeping is to establish an Application.OnTime event. I think that would be more bulletproof. Maybe something like this...

    Please Login or Register  to view this content.
    Put this in a standard code module. Change the name of the UserForm to suit.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 03-31-2019 at 07:26 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Autoclose form doesn't always close when it should?

    Interesting suggestion AlphaFrog. Could you help me understand why an Application.OnTime is better than using Sleep in a For Next?

    BTW I think I found out some of the problems with my original code (yeah it's a mess. I cannabalised code from a Progress Bar form which will explain a few things!), I had some Click events that unload the Form. They should be using mblnExitMe = True

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Autoclose form doesn't always close when it should?

    When you use Sleep in VBA, all of Excel is paused while sleeping; It doesn't output, process, or receive input.

    Application.Ontime doesn't pause Excel. It just schedules a macro to be run at some future time.

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Autoclose form doesn't always close when it should?

    Quote Originally Posted by AlphaFrog View Post
    When you use Sleep in VBA, all of Excel is paused while sleeping; It doesn't output, process, or receive input.

    Application.Ontime doesn't pause Excel. It just schedules a macro to be run at some future time.
    Thanks for the explanation AlphaFrog. (reps)

    I have shied away from Application.Ontime in case it tries to fire after I have finished with the function. I will try to rethink my approach in future.

+ 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. [SOLVED] Autoclose won't close without saving
    By vio.coman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2014, 07:01 AM
  2. [SOLVED] Why doesn't my workbook close.
    By bjkrukowski in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2012, 06:11 PM
  3. Workbook doesn't always close
    By foxguy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-28-2009, 04:06 PM
  4. User Form... built in form is so close...!
    By pianoman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2006, 08:01 AM
  5. Why doesn't my resized worksheet have a minimize or close box in .
    By Wade www in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-03-2005, 03:25 PM
  6. Excel process doesn't close?
    By Al in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2005, 11:05 AM
  7. [SOLVED] My workbook doesn't have min., max., and close symbols in the cor.
    By Sandyjo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2005, 03:06 PM

Tags for this Thread

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