1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| '*******************
Option Explicit
'### L'affectation au variant MesTitres ###
'### sera à adapter plus bas dans proc1 ###
Dim MesTitres As Variant
Dim OnTimer&
Private Declare Function SendMessage& Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow& Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String)
Private Declare Function SetTimer& Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Private Declare Function KillTimer& Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long)
Private Declare Function GetWindowText& Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long)
'___________________________
Private Sub CloseMsgBox()
Dim HwndMsgBox&
Dim i&
Dim Ch$
Dim Tampon&
Dim reponse&
For i& = LBound(MesTitres) To UBound(MesTitres)
HwndMsgBox& = FindWindow(vbNullString, MesTitres(i&))
If HwndMsgBox& > 0 Then Exit For
Next i&
If HwndMsgBox& > 0 Then
Ch$ = Space(1024)
Tampon& = Len(Ch$)
reponse& = GetWindowText(HwndMsgBox&, Ch$, Tampon&)
Ch$ = Trim(Replace(Ch$, Chr$(0), ""))
SendMessage HwndMsgBox&, &H10, 0, ByVal 0&
End If
End Sub
'___________________________
Private Sub RunTimer(Delai&)
If OnTimer& > 0 Then OffTimer
OnTimer& = SetTimer(0, 0, ByVal Delai&, AddressOf CloseMsgBox)
End Sub
'___________________________
Private Sub OffTimer()
If OnTimer& > 0 Then
OnTimer& = KillTimer(0&, OnTimer&)
OnTimer& = 0
End If
End Sub
'___________________________
Sub proc1()
'*** Code traitement avant appel à proc2 ***
'///// à ajouter à votre code ////
OnTimer& = 0
Call RunTimer(Delai:=0)
'### Mettre les titres des MsgBox à ###
'### cacher dans le Array du Variant ###
'### MesTitres. Cette instruction peut ###
'### être placée en tête de la procédure ###
'### proc1 MAIS avant l'appel à proc2 ###
MesTitres = Array("BILOU", "Microsoft Excel", "toto")
'---- Ici l'appel de proc2 (à adapter)----
Application.Run "zaza.xls!proc2"
'-----------------------------------------
Call OffTimer
'/////////////////////////////////
'*** Code traitement après appel à proc2 ***
End Sub
'******************* |
Partager