Freeze the screen

C

Charlie Mac

VBA Gerus,

I have a macro that scans word documents looking for specific text and
on large documents it slows down. Is there a way to freeze or disable
screen updates while the macro runs...to speed-up the process? Thanks
..

Take care,

Charlie from Texas
 
J

Jay Freedman

Technically, yes, but freezing the screen is the wrong technique. If the
screen is scrolling, that means you're using the Find property of the
Selection object, which forces the cursor to move and the screen to scroll.
Instead, use the Find property of a Range object that you initialize to the
range of the document. That has no effect on the cursor, the screen won't
scroll, and the macro will be faster by probably an order of magnitude.

Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
' ... do your stuff
End With

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jonathan West

VBA Gerus,

I have a macro that scans word documents looking for specific text and
on large documents it slows down. Is there a way to freeze or disable
screen updates while the macro runs...to speed-up the process? Thanks
.

Application.ScreenUpdating = False

This will greatly reduce through not entirely eliminate screen updating.

A far greater effect will be if you avoid using the Selection object and
learn to use Range object variables instead.

At its simplest do this at the start of your macro

Dim oRange as Range
Set oRange = Selection.Range

Then from there on, use oRange wherever you previously used Selection. There
are a few methods that work on the Selection that don't work on a Range, but
not very many, and there are alternatives in most cases.
 

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