How to Suspend Screen Updating

Started by taser8612, June 26, 2023, 09:58:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

taser8612

I have a fairly complex diagram that is assembled entirely through VBA in a couple minutes. I had hoped that setting the ScreenUpdating and/or the ShowChanges properties to false temporarily would speed up the build time, but have found both settings are ignored.

According to Microsoft, "If you send a large number of commands to a Microsoft Visio instance while screen updating is turned off, the Visio instance may redisplay the screen occasionally to flush its buffers." In my experience, whether true or false, there is no noticeable difference in how Visio behaves. It's like ScreenUpdating is always true, despite the value.

Hoping someone on the forum might know what that "large number" might be and if there is a work around.

Thanks!

Nikolay

How did you find out that the setting is ignored?
Was the screen still updating, even if you set ShowChanges = False?

Or do you mean that changing this property did help you to improve the performance?
There are many performance improvement tips topics here on the forum, check out this one, for example:
http://visguy.com/vgforum/index.php?topic=8948.0

taser8612

Thanks Nikolay.

I should have been more clear. I've been setting ScreenUpdating = False, and yes, the screen continues to update. I confirm the value in the immediate window. So whether true or false, the screen updates in the same manner. Setting ShowChanges to false will prevent the VBA I'm using from executing.

I looked through the tips covered in your example and had already searched the forum for answers to the behavior I'm seeing from the ScreenUpdating property but didn't find any answers.

Thanks again for taking the time to reply.

Nikolay

That sounds odd. The ScreenUpdating property is supposed to block the screen update (and it does for me):

Application.ScreenUpdating = False

For i = 1 To 1000
   ActivePage.DrawRectangle i, i, i + 1, i + 1
Next

Application.ScreenUpdating = True ' <<< the screen is repainted only here.

Please note that if you work in VBA IDE (debugger) and run this step-by-step for example, or hit a breakpoint, the screen will be repainted anyway.
This method assumes the VBA debugger is not interfering.

taser8612

My bad. Problem found. I was using a sub to insert some delays in a few spots. Having DoEvents in the loop must negate the ScreenUpdating value. If I comment it out, screen updating behaves as it should.

Thanks for setting me straight Nikolay!

Public Sub WasteTime(Finish As Long)
    Dim NowTick As Long
    Dim EndTick As Long
    EndTick = Timer + Finish
    Do
        NowTick = Timer
        DoEvents
    Loop Until NowTick >= EndTick
End Sub