Bonjour a tous, bonne fête au lecteur de ce message !

Voici mon problème, j'utilise le TCD d'Excel pour afficher les résultats de mes requetes sur une BDD

Au premier coup tout se passe bien !



Et au moment de le lancer une deuxieme fois, une chouette erreur apparait !



Ligne qui bug:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Workbooks.OpenText FileName:=App.Path & "\rq.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlNone, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
Est-ce une erreur de fermeture?

Voici mon code qui travaille avec Excel:
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
 
Public Sub Go()
 
'Déclaration des variables
Dim appExcel As Excel.Application 'Application Excel
Dim wbExcel As Excel.Workbook 'Classeur Excel
Dim wsExcel As Excel.Worksheet 'Feuille Excel
 
'Ouverture de l'application
Set appExcel = CreateObject("Excel.Application")
 
 
'Ouverture d'un fichier Excel (TCD)
Workbooks.OpenText FileName:=App.Path & "\rq.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlNone, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
 
'
Set wbExcel = appExcel.ActiveWorkbook
Set wsExcel = wbExcel.ActiveSheet
'ConstruitTCD
Set wkExcel = appExcel.Workbooks.Open(App.Path & "\rq.xls")
'Rendre excel visible
 
appExcel.Visible = True
appExcel.Run (MacPrincipal)
 
'Désallocation mémoire
Set wsExcel = Nothing
Set wbExcel = Nothing
Set wkExcel = Nothing
Set appExcel = Nothing
'Je supprime le fichier texte utilisé pour éviter tout soucis de conflit
Kill App.Path & "\rq.txt"
End Sub
 
'Pour former le fichier texte que j'envoi
Public Sub txtRQ(sequence As String)
    Form1.Visible = True
    Form1.Text1.Text = connexionServ.injectNomColonne
    Form1.Text2.Text = sequence
    Open App.Path & "\rq.txt" For Output As #3
        Print #3, connexionServ.injectNomColonne
        Print #3, sequence
    Close #3
End Sub
Ailleurs dans mon programme j'utilise KillProcess ("EXCEL.exe") pour être sur que l'utilisateur a correctement refermé Excel avant de le ré-utiliser
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
'Procédure du site developpez
Public Function KillProcess(ByVal ProcessName As String) As Boolean
    Dim svc As Object
    Dim sQuery As String
    Dim oproc
    Set svc = GetObject("winmgmts:root\cimv2")
    sQuery = "select * from win32_process where name='" & ProcessName & "'"
    For Each oproc In svc.execquery(sQuery)
        oproc.Terminate
    Next
    Set svc = Nothing
End Function