Microsoft Excel - VBA Wscript.Shell info box set to time out doesn't time out if userform is displayed

Asked By John Wirth on 24-Aug-13 06:28 AM
I am running code to show a windows pop up which times out after a couple of seconds. The code works fine, but I need it to run correctly when a userform is displayed. The userform is not modal. However, the pop up opens as it should, but does not self close.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 25 ' two minutes
Public Const cRunWhat = "MessageBoxTimer"
Sub MessageBoxTimer()
On Error Resume Next
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
    Dim AckTime As Integer, InfoBox As Object
    Set InfoBox = CreateObject("WScript.Shell")
    AckTime = 2
    Select Case InfoBox.Popup("Click OK (this window closes automatically after 2 seconds).", AckTime, "This is your Message Box", 0)
      Case 1, -1
      RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Exit Sub
    End Select
End Sub

I have also tested the code with a completely blank userform, again with show modal set to false and have the same problem. Again, the pop up times out as it should if the userorm is NOT loaded.

Harry Boughen replied to John Wirth on 24-Aug-13 06:40 PM
Hi John,
A bit out of my depth I'm afraid.  Perhaps someone in the VB area might be able to help.
Robbe Morris replied to John Wirth on 25-Aug-13 06:12 PM
I think I would approach this a little differently.  In the userform that is going to popup, run the logic for timing it out and closing it inside the userform versus trying to manage it from the parent form/opener.

That would give you pretty basic timer logic in the userform.