I can't imagine how you would do that. You can only satisfy a msgbox by clicking one of its buttons, but you can't send a click event to them, because you do not have access to the buttons as objects. You could maybe use a timer in one form to Unload the form that has the msgbox, but that is serious overkill, and I mention it as purely academic conjecture. I must agree with zemp. Create a form that looks like a message box, but do not use "msgbox." It is too restrictive.
You can try this MsgboxTimeout function in conjunction with a timer to do this job.
Place a command button (Command1) and a timer (Timer1) on your form containing the following code. Run and test the program to see the message box vanish automatically.
___
Option Explicit
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Sub Command1_Click()
Debug.Print MsgboxTimeout("This message box will automatically dismiss in 5 seconds!", vbExclamation, "Message box with timeout", 5000)
End Sub
Function MsgboxTimeout(Prompt As String, Optional Buttons As VbMsgBoxStyle, Optional Title As String, Optional TimeoutMilliSeconds As Long) As VbMsgBoxResult
If Title = vbNullString Then Title = App.Title
Timer1.Tag = Title
Timer1.Interval = TimeoutMilliSeconds
Timer1.Enabled = True
MsgboxTimeout = MessageBox(hwnd, Prompt, Title & Chr$(160), Buttons)
If Timer1.Tag = vbNullString Then MsgboxTimeout = 0 'indicates a timeout dismissal
Timer1.Enabled = False
End Function
Private Sub Timer1_Timer()
AppActivate Timer1.Tag & Chr$(160)
Timer1.Tag = vbNullString
SendKeys " "
End Sub
If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.