Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > VBA Access
VBA Access Le forum pour les questions relatives au code VBA sous Access, et à son environnement de développement VBE.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 21/02/2011, 12h00   #1
Invité de passage
 
Inscription : mars 2004
Messages : 65
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 65
Points : 1
Points : 1
Par défaut Création fichier Excel et processus toujours actif

Bonjour,

Je crée un fichier Excel via Access (pour faire un bilan) et à la fin du programme je fais :

Code :
1
2
3
 
xls.Quit
Set xls = Nothing
et pourtant le processus Excel tourne toujours et donc si j'ouvre Excel ensuite, ça ne fonctionne pas (il faut aller tuer le processus via le gestionnaire de tâches)

Est ce que quelqu'un voit où est mon pb ?
D'avance merci.
moustika est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2011, 13h44   #2
Membre du Club
 
Inscription : novembre 2009
Messages : 68
Détails du profil
Informations forums :
Inscription : novembre 2009
Messages : 68
Points : 52
Points : 52
j'ai eu le même problème mais je précise que je suis sur 2003

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
Dim oXL As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
 
Set oXL = New Excel.Application
    Set oBook = oXL.Workbooks.Open("c:\Documents and Settings\Administrateur\Mes documents\" & nomFichier)
    Set oSheet = oBook.ActiveSheet
 
'tout un tas de code très intéressant ^^
 
    Set oXL = Nothing
    Set oBook = Nothing
    Set oSheet = Nothing
utan88 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2011, 14h04   #3
Invité de passage
 
Inscription : mars 2004
Messages : 65
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 65
Points : 1
Points : 1
Merci de ta réponse.

Le pb c'est que le seul objet que j'ouvre est la connexion xls donc c'est le seul que j'ai à détruire normalement.

Code :
1
2
3
4
5
6
7
    Set xls = Excel.Application
 
    .............................
 
    xls.Quit
 
    Set xls = Nothing
moustika est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2011, 14h35   #4
Membre du Club
 
Inscription : août 2008
Messages : 86
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 86
Points : 43
Points : 43
Bonjour à tous,

J'ai eu le même problème, ainsi que de nombreux autres utilisateurs apparemment. J'ai trouvé un tuto qui permet de solutionner ce problème de manière un peu "barbare", en "tuant" le processus excel directement au niveau windows.

La fonction qui permet ceci est la suivante : (à noter que cette fonction "tue" tous les processus excel, il faut faire attention d'avoir sauvegarder les fichiers excels courants)

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
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
 
Option Compare Database
Option Explicit
 
Type strucPROCESSENTRY32
dwSize As Long ' DWORD : Size of the structure, in bytes
cntUsage As Long ' DWORD : not used (0)
th32ProcessID As Long ' DWORD : PID
th32DefaultHeapID As Long ' ULONG_PTR : not used (0)
th32ModuleID As Long ' DWORD : not used (0)
cntThreads As Long ' DWORD : Threads
th32ParentProcessID As Long ' DWORD : parent process ID
pcPriClassBase As Long ' LONG
dwFlags As Long ' LONG : not longer used (0)
szExeFile As String * 512 ' TCHAR szExeFile[MAX_PATH] name of the executable file for the process
End Type
 
Const TH32CS_SNAPPROCESS As Long = &H2
Const PROCESS_TERMINATE As Long = &H1
Const PROCESS_QUERY_INFORMATION As Long = &H400
 
Private Declare Function CreateToolhelp32Snapshot Lib "Kernel32.dll" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "Kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As strucPROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "Kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As strucPROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "Kernel32.dll" (ByVal hProcess As Long, ByVal dwExitCode As Long) As Long
 
Sub TermProcess(strProcessName As String)
 
    Dim hSnapshot As Long
    Dim lppe As strucPROCESSENTRY32
    Dim hProc As Long
    Dim Retval As Long
    Dim strPrcsName As String
 
    hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
    lppe.dwSize = Len(lppe)
    Retval = Process32First(hSnapshot, lppe)
 
    Do While Retval
        strPrcsName = Left(lppe.szExeFile, InStr(1, lppe.szExeFile, vbNullChar) - 1)
        ' Debug.Print strPrcsName, lppe.th32ProcessID
        If strPrcsName Like strProcessName Then
            hProc = OpenProcess(PROCESS_TERMINATE, 0, lppe.th32ProcessID)
            If hProc <> 0 Then
                Retval = TerminateProcess(hProc, 0)
                ' Si Retval=0 échec de la fonction TerminateProcess(..)
                Call CloseHandle(hProc)
            End If
        End If
        ' Process Suivant
        Retval = Process32Next(hSnapshot, lppe)
    Loop
 
    Call CloseHandle(hSnapshot)
 
End Sub
Met tout ceci dans un nouveau module, et quand tu veux fermer excel, tu fais appel à la fonction en ajoutant cette ligne dans ton code vba :

Code :
1
2
 
TermProcess "EXCEL.EXE"
Ca devrait marcher.

Bon courage
Glherbier est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2011, 15h06   #5
Expert Confirmé
 
Avatar de Godzestla
 
Homme
Chercheur de bonheur
Inscription : août 2007
Messages : 2 255
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 47
Localisation : Belgique

Informations professionnelles :
Activité : Chercheur de bonheur
Secteur : Industrie

Informations forums :
Inscription : août 2007
Messages : 2 255
Points : 2 979
Points : 2 979
Bonjour à tous,

moustika, tu ne pourrais pas montrer un peu plus de ton code, s'il te plait ?

Personnellement, sous 2003, je fais comme ceci et je n'ai jamais de soucis.

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
27
28
29
30
31
32
33
34
35
Sub Execute_Excel_Script(document As String, Excel_Workbook As String, Script_Folder As String, Excel_Script_File As String, Script_Name As String, Specific_param As Variant)
On Error Resume Next
Dim xlapp As Object
Dim ExcelWasNotRunning As Boolean    ' Indicateur de libération finale.
Dim FullScript As String
 
FullScript = Trim(Script_Folder) & Trim(Excel_Script_File)
 
Set xlapp = GetObject(, "Excel.Application")
If err <> 0 Then
   err.Clear
   ExcelWasNotRunning = True
   Set xlapp = CreateObject("Excel.application")
 Else
    ExcelWasNotRunning = False
End If
xlapp.Visible = True
Set XlWkb = xlapp.Workbooks.Open(FullScript)
 '
 ' ici nous lançons les macros automatiques d'Excel mais vous pouvez mettre du code
 '
XlWkb.RunAutoMacros xlAutoOpen
 
xlapp.Run Script_Name, document, Excel_Workbook, Excel_Script_File, Specific_param
 
XlWkb.Close
If ExcelWasNotRunning = True Then  'Reactivé 16/12/2010
    xlapp.Application.Quit
End If
 
Set XlWkb = Nothing
Set xlapp = Nothing
 
 
End Sub
ce code a l'avantage de laisser excel ouvert après s'il était ouvert avant.
__________________
(\ _ /) Cordialement G@dz
(='.'=)

(")-(") Vous avez des neurones. Sollicitez-les. . Si vous êtes aidé, pensez à Voter.
Godzestla est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/02/2011, 17h25   #6
Invité de passage
 
Inscription : mars 2004
Messages : 65
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 65
Points : 1
Points : 1
Voici une partie de mon code (j'ai enlevé l'extraction des donné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
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
 
Dim xls As Excel.Application
Dim db As DAO.Database
Dim R As DAO.Recordset
Dim Bilan As DAO.Recordset
Dim SQL As String
 
    'Ouvrir un objet Excel
    Set xls = Excel.Application
    xls.Visible = False
    xls.ScreenUpdating = False
 
    'Ouvrir la BDD
    Set db = CurrentDb()
 
    ' GENERATION DES BILANS
    SQL = "SELECT * FROM ...;"
 
    Set R = db.OpenRecordset(SQL)
 
    If Not R.EOF Then
 
        Do While Not R.EOF
 
            xls.Workbooks.Open "C:\....\Modèles\Bilan.xls"
 
            sql1 = "SELECT * FROM..."
 
            Set Bilan = db.OpenRecordset(sql1)
 
            xls.Sheets("Bilan").Select
            xls.Range("H11").Select
 
            Do Until Bilan.EOF
 
                'Copier les données dans Excel
                xls.ActiveCell.Offset(0, 0) = Bilan![Nom du champ1]
                xls.ActiveCell.Offset(0, 1) = Bilan![Nom du champ2]
                xls.ActiveCell.Offset(0, 2) = Bilan![Nom du champ3]
 
                Bilan.MoveNext
 
            Loop
 
            xls.Range("A22").Select
 
            xls.Sheets("Bilan").Select
 
            xls.ActiveWorkbook.SaveAs "C:\...\Bilans\Bilan_XXX" 
 
            xls.ActiveWorkbook.Close
 
            R.MoveNext
 
        Loop
 
        R.Close
 
    End If
 
    xls.ScreenUpdating = True
 
    xls.Quit
 
    Set xls = Nothing
Je reprend le code de quelqu'un donc je suis obligée de m'adapter à ce qui a déjà été fait.

Avec ce code, pas moyen de fermer le processus Excel.

Dans d'autres programmes que j'ai fait entièrement, je n'ai jamais eu ce genre de pb.

D'avance merci pour votre aide.
moustika est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2011, 04h18   #7
Membre Expert
 
Homme Pierre ANTOINE
Inscription : février 2008
Messages : 650
Détails du profil
Informations personnelles :
Nom : Homme Pierre ANTOINE
Âge : 43
Localisation : France, Côte d'Or (Bourgogne)

Informations professionnelles :
Secteur : Enseignement

Informations forums :
Inscription : février 2008
Messages : 650
Points : 1 302
Points : 1 302
Bonjour

Récemment, une longue discussion a eu lieu sur un problème semble-t-il identique.
Le problème a été résolu.

Voici la discussion en question :
[AC-2003] Comment quitter Excel

Bonne journée

Pierre
pier.antoine est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h51.


 
 
 
 
Partenaires

Hébergement Web