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

IHM Discussion :

arrêt du code car excel fermé


Sujet :

IHM

  1. #1
    Membre du Club
    Femme Profil pro
    Ingénieur environnement
    Inscrit en
    Septembre 2007
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 48
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur environnement

    Informations forums :
    Inscription : Septembre 2007
    Messages : 90
    Points : 68
    Points
    68
    Par défaut arrêt du code car excel fermé
    Bonjour,

    J'ai écrit ce code dans un formulaire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Private Sub Commande5_Click()
     
    ....
     
    Dim xlApp As Object
    Set xlApp = GetObject(, "Excel.Application")
    xlApp.Workbooks.Open "C:\mondossier\monfichier.xls"
     
    End Sub
    Malheureusement il s'arrête à cette ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set xlApp = GetObject(, "Excel.Application")
    Quand je lance Excel manuellement, et que j'achève l'exécution du code ça marche.......
    Je n'arrive pas à trouver ce qui ne va pas....
    Un petit conseil serait le bienvenue.

    D'avance merci.

    Mumu64

  2. #2
    Membre éprouvé Avatar de azertix
    Homme Profil pro
    Technicien d'assistance informatique
    Inscrit en
    Juin 2007
    Messages
    958
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien d'assistance informatique

    Informations forums :
    Inscription : Juin 2007
    Messages : 958
    Points : 937
    Points
    937
    Par défaut
    Bonjour.
    Qu'est censé faire ton code ?
    Si ma réponse vous a été utile pensez à voter Pour

    Avant de poster sur le forum Access :
    FAQ > SOURCES > COURS > FORUM > GOOGLE
    Pas de question par MP ou je mords


  3. #3
    Membre expérimenté
    Avatar de Frank
    Homme Profil pro
    Chef de projet Informatique
    Inscrit en
    Avril 2002
    Messages
    1 095
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Chef de projet Informatique
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 095
    Points : 1 392
    Points
    1 392
    Par défaut
    Voici le code proposé dans l'aide de Microsoft Access :
    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
    ' Declare necessary API routines:
    Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName as String, _
                        ByVal lpWindowName As Long) As Long
     
    Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hWnd as Long,ByVal wMsg as Long, _
                        ByVal wParam as Long, _
                        ByVal lParam As Long) As Long
     
    Sub GetExcel()
        Dim MyXL As Object    ' Variable to hold reference
                                    ' to Microsoft Excel.
        Dim ExcelWasNotRunning As Boolean    ' Flag for final release.
     
    ' Test to see if there is a copy of Microsoft Excel already running.
        On Error Resume Next    ' Defer error trapping.
    ' Getobject function called without the first argument returns a 
    ' reference to an instance of the application. If the application isn't
    ' running, an error occurs.
        Set MyXL = Getobject(, "Excel.Application")
        If Err.Number <> 0 Then ExcelWasNotRunning = True
        Err.Clear    ' Clear Err object in case error occurred.
     
    ' Check for Microsoft Excel. If Microsoft Excel is running,
    ' enter it into the Running Object table.
        DetectExcel
     
    ' Set the object variable to reference the file you want to see.
        Set MyXL = Getobject("c:\vb4\MYTEST.XLS")
    ' Show Microsoft Excel through its Application property. Then
    ' show the actual window containing the file using the Windows
    ' collection of the MyXL object reference.
        MyXL.Application.Visible = True
        MyXL.Parent.Windows(1).Visible = True
         Do manipulations of your  file here.
        ' ...
    ' If this copy of Microsoft Excel was not running when you
    ' started, close it using the Application property's Quit method.
    ' Note that when you try to quit Microsoft Excel, the
    ' title bar blinks and a message is displayed asking if you
    ' want to save any loaded files.
        If ExcelWasNotRunning = True Then 
            MyXL.Application.Quit
        End IF
     
        Set MyXL = Nothing    ' Release reference to the
                                    ' application and spreadsheet.
    End Sub

  4. #4
    Membre du Club
    Femme Profil pro
    Ingénieur environnement
    Inscrit en
    Septembre 2007
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 48
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur environnement

    Informations forums :
    Inscription : Septembre 2007
    Messages : 90
    Points : 68
    Points
    68
    Par défaut
    Bonjour,

    Pour répondre à ta question azertix, le code est censé envoyer le résultat de requêtes dans un même fichier excel puis d'ouvrir ce fichier pour qu'une macro continue à faire des manip sur le fichier excel nouvellement créé. Voici la ligne de code d'export des données dans le fichier :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ma requete", "C:\mondossier\monfichier.xls", True
    C'est pourquoi j'ai besoin qu'Excel s'ouvre à un moment donné.

    Frank, je te remercie pour le code mais le début "API" n'est pas très parlant pour moi...... Je voudrais juste comprendre pourquoi Excel ne s'ouvre pas.... Mais je vais regarder attentivement ton code.

    Merci

  5. #5
    Membre expérimenté
    Avatar de Frank
    Homme Profil pro
    Chef de projet Informatique
    Inscrit en
    Avril 2002
    Messages
    1 095
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Chef de projet Informatique
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 095
    Points : 1 392
    Points
    1 392
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ' Declare necessary API routines:
    Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName as String, _
                        ByVal lpWindowName As Long) As Long
     
    Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hWnd as Long,ByVal wMsg as Long, _
                        ByVal wParam as Long, _
                        ByVal lParam As Long) As Long
    Cette partie doit être déclarée au début de ton module.
    C'est nécessaire pour que le code puisse fonctionner.

  6. #6
    Membre du Club
    Femme Profil pro
    Ingénieur environnement
    Inscrit en
    Septembre 2007
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 48
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur environnement

    Informations forums :
    Inscription : Septembre 2007
    Messages : 90
    Points : 68
    Points
    68
    Par défaut
    Merci Frank,

    Je vais essayer ça à mon retour de vacances.....

  7. #7
    Membre du Club
    Femme Profil pro
    Ingénieur environnement
    Inscrit en
    Septembre 2007
    Messages
    90
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 48
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Ingénieur environnement

    Informations forums :
    Inscription : Septembre 2007
    Messages : 90
    Points : 68
    Points
    68
    Par défaut
    Bonjour,

    J'e n'ai pas abandonné ce fil mais je n'arrivais pas à utiliser le code que tu m'avais donné Frank, impossible de l'adapter (pas assez de maîtrise je pense). Mais j'ai quand même trouvé une solution à mon problème ! voici le code qui ouvre Excel et mon fichier par la suite.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Workbooks.Open "C:\mondossier\monfichier.xls"
    Merci quand même et à bientôt peut-être.

    Mumu64

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 15
    Dernier message: 21/11/2006, 10h13
  2. Réponses: 27
    Dernier message: 08/06/2006, 13h37
  3. [VBA-E]Importer des données de fichiers excel fermés
    Par bart64 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 20/04/2006, 11h35
  4. arrêt du code php si erreur = vrai...
    Par sam01 dans le forum Langage
    Réponses: 5
    Dernier message: 25/02/2006, 22h24

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