MsgboxTimer




Option Explicit

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_CLOSE = &H10
Private Const MsgTitle As String = "Test Message"

Private Sub Command1_Click()
With Timer1
.Interval = 2000
.Enabled = True
End With
MsgBox "I should disappear in two seconds.", , MsgTitle
End Sub

Private Sub Timer1_Timer()
Dim hWnd As Long
Timer1.Enabled = False
hWnd = FindWindow(vbNullString, MsgTitle)
Call SendMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
End Sub
Start a new project,
add a command button and a timer to the default form,
and paste this code:











( msgboxtimer.html )- by Paolo Puglisi - Modifica del 17/12/2023