IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

macro qui teste si un programme externe est en cours d'execution


Sujet :

Macros et VBA Excel

  1. #1
    Membre du Club
    Inscrit en
    Février 2004
    Messages
    197
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 197
    Points : 58
    Points
    58
    Par défaut macro qui teste si un programme externe est en cours d'execution
    Bonjour

    Je travaille avec Excel 2003

    J'ecris une macro qui lance un programme externe (avec la commande Shell).
    Le programme effectue une tache, puis termine son execution.
    La macro a besoin de savoir quand ce programme a termine

    Comment faire pour tester si le programme est toujours en cours d'execution ?

    Merci de votre aide

    Jerome

  2. #2
    Expert éminent Avatar de jfontaine
    Homme Profil pro
    Contrôleur de Gestion
    Inscrit en
    Juin 2006
    Messages
    4 754
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Contrôleur de Gestion

    Informations forums :
    Inscription : Juin 2006
    Messages : 4 754
    Points : 9 396
    Points
    9 396
    Par défaut
    Bonjour,

    Il existe une API qui te permet de faire ca sans trop d'effort

    Tout d'abord tu copies ce code dans un module
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Option Explicit
     
    Public Const SEE_MASK_DOENVSUBST As Long = &H200
    Public Const SEE_MASK_IDLIST As Long = &H4
    Public Const SEE_MASK_NOCLOSEPROCESS As Long = &H40
    Public Const SW_HIDE As Long = 0
    Public Const SW_SHOW As Long = 5
    Public Const WAIT_TIMEOUT As Long = 258&
    Public Type SHELLEXECUTEINFOA
        cbSize As Long
        fMask As Long
        hwnd As Long
        lpVerb As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShow As Long
        hInstApp As Long
        lpIDList As Long
        lpClass As String
        hkeyClass As Long
        dwHotKey As Long
        hIcon As Long
        hProcess As Long
    End Type
    Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
    Public Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long
    Public Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef lpExecInfo As SHELLEXECUTEINFOA) As Long
    Public Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
     
    Public Function ShellWait(ByRef vsCmdLine As String, Optional ByRef vsParameters As String, Optional ByRef vsCurrentDirectory As String = vbNullString, Optional ByVal vnShowCmd As Long = SW_SHOW, Optional ByVal vnTimeOut As Long = 200) As Long
    Dim lpShellExInfo As SHELLEXECUTEINFOA
        With lpShellExInfo
            .cbSize = Len(lpShellExInfo)
            .lpDirectory = vsCurrentDirectory
            .lpVerb = "open"
            .lpFile = vsCmdLine
            .lpParameters = vsParameters
            .nShow = vnShowCmd
            .fMask = SEE_MASK_DOENVSUBST Or SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_IDLIST
        End With
        If ShellExecuteEx(lpShellExInfo) Then
            Do While WaitForSingleObject(lpShellExInfo.hProcess, vnTimeOut) = WAIT_TIMEOUT
                DoEvents
            Loop
            GetExitCodeProcess lpShellExInfo.hProcess, ShellWait
            CloseHandle lpShellExInfo.hProcess
        Else
            ShellWait = vbError
        End If
    End Function
    Et tu utilises en appelant la fonction
    Jérôme

Discussions similaires

  1. Macro qui teste si un programme externe est en cours d'execution
    Par tarbault dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 07/01/2014, 11h11
  2. Réponses: 3
    Dernier message: 23/04/2010, 18h06
  3. Macro qui teste la colonne ou se trouve le bouton ?
    Par Drvibe dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 23/02/2008, 21h01
  4. Savoir si un programme externe est déjà lancé
    Par _iri_ dans le forum Général Python
    Réponses: 4
    Dernier message: 08/10/2006, 18h09
  5. faire un test sur un programme externe
    Par marieheraud dans le forum Windows
    Réponses: 3
    Dernier message: 02/09/2004, 18h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo