Hack 86 Display a "Please Wait" Message
to take forever to complete? If this is a problem with your macro,
you can have Excel display a "Please
Wait" message to the user.Most users expect code to run and
complete almost instantaneously. Sadly, this doesn't
always happen. Recorded macros in particular generally take much
longer to complete than well-written VBA code. To add to the problem,
Excel VBA code is generally slower than a lot of other types of code.Fortunately,
you can use a bit of extra code to create a "Please
Wait" message so that users know the code is running
and Excel has not locked up on them! Unfortunately, one of the more
popular ways to let users know code is running is via the use of an
Excel progress meter.There are two problems with this method.
First, the progress meter can slow down your code even more,
compounding the issue. Second, your slow code must be caused by a
loop, and you cannot use the macro recorder to create a loop.We prefer using VBA code, such as the
following DoIt macro, which uses a rectangle from
the Drawing toolbar.
Sub DoIt( )
Application.ScreenUpdating = True
With Sheet1.Shapes("Rectangle1")
.Visible = msoTrue = (Not Sheet1.Shapes("Rectangle1").Visible)
End With
'Toggling sheets Forces Rectangle1 to show while code is running
Sheet2.Select
Sheet1.Select
End Sub
To use this
code, add a rectangle from the Drawing toolbar to any sheet in the
appropriate workbook. While the rectangle is selected, click in the
Name box and name the rectangle Rectangle1 (if
it's not already called that).Enter the text you want displayed while
your code is running, and format, position, and size the rectangle as
desired. Enter the preceding DoIt macro into a
standard module of your workbook. If necessary, change
Sheet1 in the code to the CodeName of the sheet on
which you placed Rectangle1. (For more information on CodeNames, see
[Hack #83].) Then select Tools
from within Excel. This will hide Rectangle1 completely.At the very start of the slow code, place the following:
Run "DoIt"
Application.ScreenUpdating = False
The use of
Application.ScreenUpdating =
False stops screen flicker and speeds up macros.
At the very end of the slow code, simply place
Run "DoIt". Then run
your macro as usual.
• Table of Contents• Reviews• Reader Reviews• Errata• AcademicExcel HacksBy
David Hawley, Raina HawleyPublisher: O''ReillyPub Date: March 2004ISBN: 0-596-00625-XPages: 304The tips and tools in Excel Hacks
include little known "backdoor" adjustments for everything
from reducing workbook and worksheet frustration to hacking
built-in features such as pivot tables, charts, formulas and
functions, and even the macro language. This resourceful,
roll-up-your-sleeves guide shows you new ways to make Excel
do things--from data analysis to worksheet management to
import/export--that you never thought possible.
Excel Hacks increases productivity with
Excel and gives you hours of "hacking" enjoyment along the
way.