'place in a module
Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public 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
Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Public Const NV_CLOSEMSGBOX As Long = &H5000&
Public Const API_FALSE As Long = 0&
Public Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
KillTimer hWnd, idEvent
Dim hMessageBox As Long
'Replace 'Self Closing Message Box' with the title you gave to your message box.
hMessageBox = FindWindow("#32770", "Self Closing Message Box")
If hMessageBox Then
Call SetForegroundWindow(hMessageBox)
SendKeys "{enter}"
End If
Call LockWindowUpdate(API_FALSE)
End Sub
'place on your form
Private Sub Command1_Click()
'Replace the '4000' below with the number of milliseconds the message box
'will appear. 1000 milliseconds = 1 second
SetTimer hWnd, NV_CLOSEMSGBOX, 4000&, AddressOf TimerProc
Call MessageBox(hWnd, "Watch this message box close itself after four seconds", _
"Self Closing Message Box", vbInformation)
End Sub