OzGrid

Excel: Please Wait Message for Slow or Long Running Excel Macros

< Back to Search results

 Category: [Excel]  Demo Available 

Excel: Please Wait Message for Slow or Long Running Excel Macros

 

Download Workbook Example of Wait Message Macro

 

Got any Excel/VBA Questions? Free Excel Help

Ever had one of those macros that seem to take forever to complete? Recorded macros in particular generally take much longer than well written VBA code. Most users in this day and age expect code to run and complete almost instantaneously once they click 'the button'. Unfortunately, Excel VBA code is generally slower than a lot of other code types.

If this is a problem with your code we can have Excel display a "Please Wait" message to the user. This way they know that code is running and Excel has not locked up on them! Unfortunately, one of the more popular ways to let the user know that code is running is via the use of a progress meter. There are 2 problems with this method;

  1. The Progress Meter Itself Can Slow Down Your Code Even More, Compounding The Problem.
  2. Your Slow Code Must Be Because Of A Loop And You Cannot Use The Macro Recorder To Create A Loop.

The method that I prefer is to use VBA code that makes use of a Rectangle from the Drawing Toolbar

Sub DoIt()

	Application.ScreenUpdating = True

		With Sheet1.Shapes("Rectangle 1")

			.Visible = msoTrue = (Not Sheet1.Shapes("Rectangle 1").Visible)

		End With

	'Toggling sheets Forces Rectangle 1to show while code is running

	Sheet2.Select

	Sheet1.Select
End Sub

  1. To Use The Same Code Add A "Rectangle", From The Drawing Toolbar To Any Sheet In The Appropriate Workbook.
  2. While It Is Selected, Click In The Name Box (Left Of Formula Bar) And Re-Name It "Rectangle 1" (If It's Not Already)
  3. Enter The Text You Want Displayed While Your Code Is Running And Format The Rectangle As Desired.
  4. Position And Size It As Desired.
  5. Copy The Macro "DoIt" Above Into A Standard Module Of Your Workbook.
  6. If Needed, Change "Sheet1" Of The Code To The CodeName Of The Sheet You Have Placed "Rectangle 1" On. A Sheets CodeName Is The Name NOT In Parenthesis While Looking In The Project Explorer Of The VBE.
  7. Go To Tools>Macro>Macros And Run "DoIt" From Within Excel. This Will Completely Hide "Rectangle 1"
  8. At The Very Start Of The 'Slow Code' Place
Run "Doit"

Application.ScreenUpdating = False

The use of

Application.ScreenUpdating = False

See: Stop Screen Flicker and Speed up Macros

  1. At The Very End Of Your Slow Code Simply Place
    Run "Doit"

All you now need to do is run your macro as normal. You can of course use the macro in any Workbook simply by following the steps above.

 

See also:

Index to Excel VBA Code
Excel: Reverse Cell Text/Content
Add Excel Right Click Menu
Delete Rows Meeting Condition/Criteria
Worksheet Change Event: Automatically Run Excel Macros When a Cell Changes
Saving an Excel Workbook/File as a Cell Text

 

See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)