Why don't disableing screen update work in VBA?

F

Frank

Why do I experience screen flickering in spite of disabling the screen update?

The following macro searches through a document and removes redundant table
headings:

Sub TrimRedundantTableHeadings()

Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = False
Selection.Find.ClearFormatting
With Selection.Find
.Text = "No table output."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
Selection.TypeBackspace
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.TypeBackspace
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
If Selection.Text <> "" Then Selection.TypeBackspace
Selection.TypeBackspace
Loop
End With
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
End Sub


Thanks, Frank
 
J

Jean-Guy Marcil

Frank was telling us:
Frank nous racontait que :
Why do I experience screen flickering in spite of disabling the
screen update?

Here is the text from the online help:

<quote>
Remarks
The ScreenUpdating property controls most display changes on the monitor
while a procedure is running. When screen updating is turned off, toolbars
remain visible and Word still allows the procedure to display or retrieve
information using status bar prompts, input boxes, dialog boxes, and message
boxes. You can increase the speed of some procedures by keeping screen
updating turned off. You must set the ScreenUpdating property to True when
the procedure finishes or when it stops after an error.
<unquote>

The key words here are "most display changes ".
Basically, and I do not know enough about the display processes in Windows
and/or Word to tell you why, but ScreenUpdating does speed up execution by
not letting the user see everything the macro does, but if you have a
longish macro that does hundreds of operation (Try your macro on a document
containing 50 pages and many instances of the text to be replaced. Then try
it without ScreenUpdating...), the active window will not only flicker, but
also get "distorted". OTOH, if you do not use ScreenUpdating , then the user
will see everything as Word tries to keep the display up to date with the
macro, which it cannot really. Then you might either hang Word or get a
white window.
An alternative is to make the window (or the application) invisible during
the process. This is even faster, no flickering, but might freak out the
users...

Bottom line is that it is better to use it, especially if you use the
selection object. If you use the Range object instead, you get no flickering
and the ScreenUpdating is not really necessary in most cases (when using a
range object).
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Howard Kaikow

The bottom line is that in every version of Word I've used, even those with
WordBasic, ScreenUpdating has always had a mind of its own.

Indeed, there appear to be particular actions that will tun on screen
updating even tho you have it set off.

I've given up. I just try to minimize activatioin/opening/closing of
documents, sprinkle a few ScreenUpdating statements hither and yon, and
hope.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top