MsgBox temporaire qui ne se ferme pas

benjy555

XLDnaute Junior
Salut,

mon pb est simple, je place ce code de msgbox temporaire basique dans "thisworkbook" est au bout des 10 secondes, le message devrait se fermer. Mais rien, la fenêtre reste active indéfiniment...


Private Sub Workbook_Open()

CreateObject("Wscript.Shell").Popup "blabla", 10, "blabla ", vbExclamation

End Sub


comment régler cela ? sur excel 2010 ( PC )

merci
 

Pierrot93

XLDnaute Barbatruc
Re : MsgBox temporaire qui ne se ferme pas

Bonjour,

oui depuis la version 2007 ne se ferme plus automatiquement... Sujet déjà abordé ici, fais une petite recherche sur le forum il doit y avoir des solutions de contournement, avec userform entre autre...

bon après midi
@+
 

benjy555

XLDnaute Junior
Re : MsgBox temporaire qui ne se ferme pas

on m'a donné une solution sur un autre forum :

Private Sub Workbook_Open()
Select Case Popup("Voulez vous executer la maj ?", 10, "Mise à Jour", _
vbInformation + vbOKCancel + vbDefaultButton2)
Case -1
call maj
Case vbOK
call maj
Case vbCancel
MsgBox "MAJ Canceled"
exit sub
End Select
End Sub


puis dans un module :

Function Popup(ByVal Prompt As String, _
Optional ByVal SecondsToWait As Integer = 0, _
Optional ByVal Title As String = "", _
Optional ByVal Buttons As VbMsgBoxStyle = vbOK) As VbMsgBoxResult
'Show a popup and wait some seconds, returns -1 if the user has not made a selection.
' Solve the problem that wss.Popup doesn't close some times when called directly from VBA
Dim fso As Object 'FileSystemObject
Dim wss As Object 'WshShell
Dim TempFile As String
On Error GoTo ExitPoint
Set fso = CreateObject("Scripting.FileSystemObject")
Set wss = CreateObject("WScript.Shell")
With fso
TempFile = .BuildPath(.GetSpecialFolder(2).Path, .GetTempName & ".vbs")
With .CreateTextFile(TempFile)
.WriteLine "Set wss = CreateObject(""WScript.Shell"")" & vbCrLf & _
"i = wss.Popup(""" & Prompt & """," & SecondsToWait & ",""" & Title & _
"""," & Buttons & ")" & "" & vbCrLf & _
"WScript.Quit i"
.Close
End With
End With
Popup = wss.Run(TempFile, 1, True)
fso.DeleteFile TempFile, True
ExitPoint:
End Function
 

Discussions similaires

Statistiques des forums

Discussions
312 333
Messages
2 087 378
Membres
103 529
dernier inscrit
gonzi