Update: ANSWER is at bottom of this top post, thanks.
hi, i am trying to get a message box to close after a specific amount of time. as with some other examples below, i would like to have the variables for: time & message in the call, eg:
call goMB (seconds) "message"
if related, other call examples are:
Sub goBEEPS(B As Long, t As Double) 'gobeeps (2), (0.5) 'BEEPS SECS
For B = B To 1 Step -1
Beep
x = Timer 'err var not defined, not setup to work under option explicit
Do
DoEvents
dt = Timer - x
If dt < 0 Then dt = dt + 86400 '86400 no. seconds in a day, in case hit midnight & timer went down to 0
Loop Until dt >= t
Next
End Sub
Sub goTIMER(NumOfSeconds As Long) 'in (seconds eg: 0.5) as: gotimer (1) 'seconds
Application.Wait now + NumOfSeconds / 86400#
Application.EnableEvents = True 'EVENTS
End Sub
'----------
SOME EXAMPLES OF TIMED MESSAGE BOXES FOUND:
CreateObject("WScript.Shell").PopUp "Message", 5 'new, need a call sub goMB() "msg", seconds
Sub goMBA() 'Messagebox Timer, works but need to modify as: call goMB (seconds) "msg"
Const Title As String = "Self closing message box"
Const Delay As Byte = 3 'seconds
Const wButtons As Integer = 16 'Buttons + icon
Dim wsh As Object, MSG As String
Set wsh = CreateObject("WScript.Shell")
'MSG = "the date is: " & Date
MSG = Space(10) & "Hello," & vbLf & vbLf & "the date is: " & Date
wsh.Popup MSG, Delay, Title, wButtons
Set wsh = Nothing
Application.EnableEvents = True 'EVENTS
End Sub
Sub goMBB() 'in secs after: strpopmsg,
Dim strPopMsg As String
strPopMsg = "TEST 1" '& vbCr '& "TEST 2"
CreateObject("WScript.Shell").Popup strPopMsg, 1, "Msg frm X", 64 '2 - 15 secs, not consistant
Application.EnableEvents = True 'EVENTS
End Sub
Sub goMBC() 'yes but inconsistant time
Dim AckTime As Integer, InfoBox As Object
Set InfoBox = CreateObject("WScript.Shell")
'Set the message box to close after 10 seconds
AckTime = 3
Select Case InfoBox.Popup("Click OK (this window closes automatically after 3 seconds).", AckTime, "This is your Message Box", 0)
Case 1, -1
Exit Sub
End Select
End Sub
Sub goMBE() 'new example
Dim t As Integer, obj As Object
Set obj = CreateObject("WScript.Shell")
t = 3 '<<<close after 3 sec.
Select Case obj.PopUp("Click OK (or wait " & t & " secs)", t, "msgbox", 0)
Case 1, -1
Exit Sub
End Select
End Sub
========== ANSWER:
Sub goMB(Msg As String, Wait As Long) 'CALL AS: goMB "your message", 3
CreateObject("WScript.Shell").PopUp Msg, Wait
End Sub
goMB "Test xxx", 3 'works, without using the word Call in front