In Microsoft Excel, you cannot display a message box at the same time a
second macro is running. However, you can simulate a message box with a
text box when using a Visual Basic for Applications macro. To do this, you
would create a text box and position it on the screen at an appropriate
location. With code, you can present the text box, run your second
subroutine, and, at the conclusion of the subroutine, delete the text box.
The example in this article demonstrates this process. You can change the
design of the text box to look anyway you want. The following example gives
you just one way to display it.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For information about showing a message box in Excel 97 for Windows and
Excel 98 Macintosh Edition, please see the following article in the
Microsoft Knowledge Base:
OFF97: How to Show a "Now Processing" Dialog While Macro Runs
Visual Basic Code Example
- Type your name in cell A1 of Sheet1 in a new workbook.
- On the Insert menu, click Macro, and then Module.
- On the new module sheet, type the following two subroutines:
' Select the first worksheet.
' Create a text box on the active worksheet.
ActiveSheet.TextBoxes.Add(215, 195, 91.5, 60).Select
' Store the name of Worksheet in variable StoreWSNM.
StoreWSNM = ActiveSheet.Name
' Store the name of Text Box in variable StoreNM
StoreNM = Selection.Name
' Set the Font and Border properties of the text box.
.Name = "Arial"
.FontStyle = "Bold"
.Size = 20
.LineStyle = xlContinuous
.ColorIndex = 1
.Weight = xlThick
'Set round corners for the text box.
.RoundedCorners = True
'Set message text color to black.
.Interior.ColorIndex = 15
'Assign message text to the text box.
.Characters.Text = "Please Wait..."
' Actual macro that will run while Please Wait...
' message is being displayed.
' Makes sure the proper Worksheet is selected.
' Makes sure the proper text box is selected.
' Deletes the Please Wait... text box.
' Note that the Please Wait... text box will be displayed
' until this macro has completed.
' Select A1 and copies it.
' Set loop to occur 5 times.
For LoopIt = 1 To 5
' Move down one row and paste the contents of A1.
' Waits one second before looping.
' NOTE: This is only done for demonstration purposes to
' slow down the macro so the Please Wait text box will
' be displayed for at least 5 seconds.
Application.Wait Now + TimeValue("00:00:01")
- On the Tools menu, click Macro. In the Macro box, select the macro
called DisplayTextMsgBox, and click the Run button.
NOTE: If your second macro will be selecting other worksheets while
running, you may want to turn off screen updating at the beginning
of the second macro. This will make sure the Please Wait text box
remains on screen while that macro runs. You can use
Application.ScreenUpdating = False to turn off screen updating.