0

I have following macro as time based run

Application.OnTime TimeValue("12:2:20"), "ADPATEL"

what I want is to popup msg box before 3 sec and close it automatically in 3 seconds

Have tried following method but it didn't close msgbox automatically

   Dim AckTime As Integer, InfoBox As Object

 Set InfoBox = CreateObject("WScript.Shell")
 AckTime = 3
 Select Case InfoBox.Popup("Click OK or do nothing within 3 seconds.", _
 AckTime, "This is your Message Box", 0)

 Case 1, -1
 Exit Sub
End Select

Any help is appriciated

Arshit patel
  • 133
  • 1
  • 10

1 Answers1

1

Try this code, please:

Sub testPopUpMess()
 Select Case CreateObject("wscript.shell").popup("Click OK or do nothing within 3 seconds.", _
                                                            3, "This is your Message Box", 64)
     Case 1: MsgBox "OK": Exit Sub
     Case Else: MsgBox """OK"" button not pressed..."
 End Select
End Sub

Anyhow, your code should work as it is... I only avoided variables to be declared and split the messages in case of pressing "OK" or closing by itself.

Do you use Excel 2007? I heard that it has such a strange behavior. If this is the case, you should use an a little more complicated method using API calls. I can help with a piece of code. It looks that Tim Williams pointed for such a solution.

FaneDuru
  • 38,298
  • 4
  • 19
  • 27