'
'MODELE PATRICKTOULON
'======================================================
' !! TEMPORISER LE VRAI MSGBOX DE VBA !!
'catégorie boite de dialogue
'Temporisation du vrai msgbox de vba
'Auteurs:patricktoulon sur exceldownload
'Version :1.0; de patricktoulon
'Utilisation des api setTimer et KillTimer
'======================================================
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32.dll" (ByVal hwnd As LongPtr, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As Long
Private Declare PtrSafe Function KillTimer Lib "user32.dll" (ByVal hwnd As LongPtr, ByVal nIDEvent As Long) As Long
#Else
Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As Long
Private Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
#End If
Dim MsgBoxTitle
Dim MsgBoxCloseD As Boolean
Dim TimerID&
Sub test1()
MsgBoxX "le message", vbOKOnly, "letitre", DelayOfResponse:=2
End Sub
Function MsgBoxX( _
message As String, _
Optional style As VbMsgBoxStyle = vbOKOnly, _
Optional titre As String = "", _
Optional helper As String = "", _
Optional ByVal contexte As Long = 0, _
Optional ResponseByDefault As Boolean = False, _
Optional DelayOfResponse As Long = 0)
Dim Response$
titre = IIf(titre = "", "Message Excel!", titre)
MsgBoxTitle = titre: MsgBoxCloseD = False:
If DelayOfResponse > 0 Then TimerID = SetTimer(0, 0, DelayOfResponse * 1000, AddressOf CloseMsgBox)
Response = MsgBox(message, style, titre, helper, contexte)
If TimerID <> 0 Then KillTimer 0, TimerID: TimerID = 0:
'réponse "timeout!!" ou le bouton par defaut selon l'argument "ResponseByDefault"
If MsgBoxCloseD And Not ResponseByDefault Then Response = "timeOut!!"
MsgBoxX = Response
End Function