+ Reply to Thread
Results 1 to 6 of 6

to pause an application.wait loop

  1. #1
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    to pause an application.wait loop

    I have an application.wait that I want to pause/break but I couldn't find a good way to do it. It seems no actions (selecting cells, pressing buttons, etc.) are allowed when it's running. Pressing keyboard Esc seems to finish the rest of the counter (c) faster. But how to stop the pause the loop at will (I don't want a counter)? Many thanks!

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: to pause an application.wait loop

    Try putting this inside your For loop:
    Please Login or Register  to view this content.
    That will allow you to break out of the macro but I don't believe you can do any user interface activity at all if a macro is running.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    Re: to pause an application.wait loop

    Thank you Jeff. Is there a way to achieve what I want to do? I don't want a counter to predetermine how many times (or how long) the loop runs. I want to do something to stop scrolling at will. Maybe other ways such as ontime - an ontime routine within a loop?

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: to pause an application.wait loop

    Not sure what you are trying to achieved, but if you want a "window scroller", then try this :

    Please Login or Register  to view this content.
    The hotkey to be used is the ' key (the one exactly under escape key at top left of keyboard), as set by this statement :
    Application.OnKey "`", "AutoScroll_Toggle"

    To run the code, run the AutoScroll_Start sub, then you can pause/unpause anytime using the hotkey.
    If you don't need the scroller anymore, run the AutoScroll_Stop sub (since the scroller takes CPU time, it is wise to stop it when no longer needed).

  5. #5
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    Re: to pause an application.wait loop

    Thanks Karedog. This is exactly what I was looking for! When I close the workbook, there is no need to run the stop sub so it won't take up resources? And when it's paused, it's not adding any overhead? I don't know much about how hot key related actions affect the performance yet.
    Last edited by aprildu; 02-24-2016 at 09:17 PM.

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: to pause an application.wait loop

    You are welcome, thanks for the rep. points.
    You can check the CPU and memory usage used by any program (Excel in this case), by opening and examining windows task manager. For modern CPU, this almost cost nothing, but it is still better a good practice to stop the macro once you don't need it anymore, because something unexpected could be happenned (could be anything) during the work of this "continous" macro, and this could lead to totally crash Excel, so it is wise to stop the macro once you don't need it any longer. And if you run another macro during the work of this scroller macro, you could experience a bad performance macro, since the vba by design is not multithreading, so a code has to wait another code to complete before it can run.

+ 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. Reflections WRQ VBA Macro Timer, Pause, or Wait command
    By tpollard1 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 5
    Last Post: 05-29-2015, 05:20 PM
  2. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  3. [SOLVED] Help with Application.OnTime (was Application.Wait Now)
    By Walter12 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-29-2012, 01:18 PM
  4. wait/pause during loop
    By _Terry_ in forum Excel General
    Replies: 4
    Last Post: 07-04-2008, 03:22 PM
  5. pause vba action without using Application.Wait?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2005, 03:15 PM
  6. application.wait help
    By flowtester in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-04-2005, 11:55 AM
  7. Application.wait... won't!
    By Peter Rooney in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-08-2005, 11:05 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