Statement to force the application's screen to update

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
My code resizes my userform, reducing its height by half. Then my code lets application.screenupdating = false.

But when screenupdating becomes false, the lower half of the userform remains frozen on the screen.

Is there a statement to force Excel to update its display before the next line in the code is initiated? I tried DoEvents with no success.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I can use "Me.Repaint" userform. No luck. It's like no matter what I do, Excel runs through the resize statements so fast that once it reaches the screenupdating statement, it still hasn't redrawn the userform even if I specifically tell it to repaint before turning off screenupdating.

Tried a do loop to 1,000,000 and that has exactly the same results.
 
Upvote 0
Code:
Application.Wait Now + TimeValue("00:00:01")
Application.ScreenUpdating = False
For i = 0 To 207 Step 20.7
    Label3.Width = i
    Label4.Caption = Int((i / 207) * 100) & "%"
    Application.Wait Now + TimeValue("00:00:01")
    Me.Repaint
    DoEvents
Next
Unload Me
[FONT=Times New Roman]Exit Sub[/FONT]

The first wait method comes between a series of resize and enabled/disabled statements that swap between two states on the same userform.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Without that first wait method, the userform appears in both states simultaneously when screenupdating becomes false; like catching a baseball flying on a camera with a low shutter-speed, the userform is distended and the newly-visible progress bar awkwardly overlaps the old frame.
<o:p> </o:p>
The second application wait method is important because without it the code runs so fast it’s impossible to observe the progress bar advancing. The doevents is critical because without it, the form does not update until the code finishes running.
<o:p> </o:p>
I only wish I could set the interval on Wait lower than one second. But that won’t matter for the final application, because it will be waiting several seconds between each update anyway, as the pivot tables are updated and the sheets print out.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top