+ Reply to Thread
Results 1 to 4 of 4

VBA Loop Freezes Excel if mouse is moved while Userform is loading - File Attached

  1. #1
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    VBA Loop Freezes Excel if mouse is moved while Userform is loading - File Attached

    Hello, I have a custom Userform which loads a loop that keeps a running clock on a label on the Userform. I have a shape on my sheet which I click to show the Userform. When the Userform initializes it sets a global variable called "Running" to True. In the Userform's Activate procedure I call the "timeAnimation" procedure (located in Module1) if "Running" is True. Closing the Userform sets "Running" to False.
    Everything works fine when the Userform is loaded without moving the mouse, (Click the shape on the sheet, and then don't move the mouse until the Userform shows) but if I click the shape on the sheet to show the Userform, and then immediately move my mouse before the Userform shows, everything freezes and I have to use CTRL - BREAK to stop the "timeAnimation" loop which is freezing Excel.

    I have tried adding a wait or sleep line in "timeAnimation" to allow the Userform to load before it starts the loop, this made no difference.

    Any help is greatly appreciated!



    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: VBA Loop Freezes Excel if mouse is moved while Userform is loading - File Attached

    It is unwise to use infinite loop like that in VBA for event demanding job like this one.

    VBA is a single threaded process, it has been already using all of its power for calc etc, nothing left for doing "multiprocessing" like capturing events and run other code at the same time.

    Instead of infinite loop using Do..Loop (with DoEvents, Sleep, or whatever that give placebo effect of "giving a rest time", in hope that "VBA should be able handle other job on this rest period"), it is better using Application.OnTime for scheduling the job, so there is almost no strain to the VBA process at all.

    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: VBA Loop Freezes Excel if mouse is moved while Userform is loading - File Attached

    I will give that a try. Thanks!

    Seems to work! Awesome!
    Last edited by unit285; 04-02-2023 at 11:27 PM.

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

    Re: VBA Loop Freezes Excel if mouse is moved while Userform is loading - File Attached

    You are welcome, thanks for marking the thread as solved and rep.points given.

    Regards

+ 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] Excel freezes after Userform opens
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2022, 12:11 PM
  2. Excel Freezes and Crashes During Do Until Loop If Ran More Than Once
    By bwink88 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-30-2020, 04:12 PM
  3. [SOLVED] Excel freezes when I use the mouse wheel on an xlsm file...
    By Ulnarian in forum Excel General
    Replies: 3
    Last Post: 05-23-2020, 10:44 AM
  4. Replies: 1
    Last Post: 01-19-2019, 09:04 PM
  5. Excel not calculating properly if mouse moved
    By fargo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2017, 09:25 AM
  6. Editing listbox items in Dblclick event freezes Excel unless mouse moves over listbox
    By muneebmansoor in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-28-2013, 02:21 PM
  7. Loading a userform when opening a xls file
    By cutsygurl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2006, 02:43 PM

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