Excel message box dismissal code no longer working
I have this little Auto Open sub in Excel 2013 which opens a message box and closes it after 1 second.  Its been working for months now all of a sudden it stopped working.  I experimented with different AckTimes and it still refuses to close the message box. If I name the sub anything other than Auto_Open it works fine. Please advise.
Sub Auto_Open()
    Dim AckTime As Integer, InfoBox As Object
    Set InfoBox = CreateObject("WScript.Shell")
    'Set the message box to close after x seconds (AckTime)
    AckTime = 1
    Select Case InfoBox.Popup("Refreshing Data. Please Wait for DONE message . . ", _
    AckTime, "Data Refresh", 0)
        Case 1, -1
            Exit Sub
    End Select
End Sub


  • Edited by StuThomson1 Thursday, July 23, 2015 3:18 PM
July 22nd, 2015 6:02pm

It's a Windows issue, you were lucky if it has worked in the past.

I've played around with such code in the past and have found that it isn't stable. Sometimes the message box disappears, sometimes not, sometimes after the number of seconds, sometimes immediately.

Add a Userform to your project with a Label that shows your message and use this code to show it:

Sub Show_Userform1()
  Dim T As Single
  'Load the form
  Load UserForm1
  With UserForm1
    'Show it and return immediately
    .Show vbModeless
    'Wait till the form is visible
    Do
      DoEvents
    Loop Until .Visible
    'Get the timer in seconds
    T = Timer
    On Error GoTo ExitPoint
    'Wait a second or finish if the form is closed manually
    Do
      DoEvents
    Loop Until Timer > T + 1 Or Not .Visible
    'Close the form
  End With
ExitPoint:
  Unload UserForm1
End Sub

BTW, Auto_Open is obsolete, use Workbook_Open (within code module "ThisWorkbook") instead.

Andreas.

Free Windows Admin Tool Kit Click here and download it now
August 17th, 2015 10:12am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics