Tom’s Tutorials for Excel: Automatically Dismiss a Message Box

Tom’s Tutorials for Excel: Automatically Dismiss a Message Box

This example shows how to automatically dismiss a message box after a specified period of time. The message box is shown, then automatically dismisses itself after 10 seconds.

Here’s the example macro:

Sub MessageBoxTimer()
    Dim AckTime As Integer, InfoBox As Object
    Set InfoBox = CreateObject("WScript.Shell")
    'Set the message box to close after 10 seconds
    AckTime = 10
    Select Case InfoBox.Popup("Click OK (this window closes automatically after 10 seconds).", _
    AckTime, "This is your Message Box", 0)
        Case 1, -1
            Exit Sub
    End Select
End Sub


Share Button
Posted in Tom's Tutorials for Excel
Tags: , , , , , , , , , , ,
2 comments on “Tom’s Tutorials for Excel: Automatically Dismiss a Message Box
  1. Colin Delane says:

    Hi Tom
    I found your code for dismissing a message box (a great idea and a useful addition to my VBA toolbox, thanks), and added it to a project. It worked for a few times and then stopped (box displays but doesn’t timeout??) – and I can’t work out why!

    I tried a reset of the event handler (Application.EnableEvents = True) but to no avail.

    Any thoughts/suggestions?

    Many thanks
    Col Delane
    Perth, Western Australia

  2. Colin Delane says:

    Hi Tom
    (Take two – error in my email address in 1st post)
    I found your code for dismissing a message box (a great idea and a useful addition to my VBA toolbox, thanks), and added it to a project. It worked for a few times and then stopped (box displays but doesn’t timeout??) – and I can’t work out why!

    I tried a reset of the event handler (Application.EnableEvents = True) but to no avail.

    Any thoughts/suggestions?

    Many thanks
    Col Delane
    Perth, Western Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*