Lancement executable via VBA
Bonjour,
Quelqu'un saurait-il m’expliquer en détail le code ci dessous (tout ce qu'il y a après la commande Shell) ainsi que la finalité des dll chargées
Code:
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
| Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Function Lance_Exe(ByVal Executable As String, Optional ByVal Parametres As String = "") As Boolean
Const SYNCHRONIZE = &H100000
Const WAIT_TIMEOUT = &H102&
Const TIMEOUT = 100
Dim RetVal, Handle, PIDexe As Long, retour As Boolean
retour = False
PIDexe = Shell(Executable & " " & Parametres, vbNormalFocus)
If PIDexe > 0 Then
Handle = OpenProcess(SYNCHRONIZE, True, PIDexe)
Do
RetVal = WaitForSingleObject(Handle, TIMEOUT)
If RetVal <> WAIT_TIMEOUT Then Exit Do
DoEvents
Loop
CloseHandle (Handle)
retour = True
End If
Lance_Exe = retour
End Function |
J'aurais peut être du poster dans le forum VB, mais je me sers de cette fonction dans le VBA Excel pour lancer des exécutables.
Merci d'avance