en fait tu oublies de supprimer ta référence à excel :
ça c'est bien :
Wxls.Workbooks.Close()
Wxls.Quit()
Wxls =Nothing
mais il faut le mettre dès que tu n'utilises plus excel
Autre façon de faire :
<DllImport("user32.dll", SetLastError:=True)> _
Private Function GetWindowThreadProcessId(ByVal hWnd As Integer, _
ByRef lpdwProcessId As Integer) As Integer
End Function
Public Function fnRecupProcessId(ByVal hWnd As Integer) As Integer
Dim R As Integer
Dim RetVal As Integer = GetWindowThreadProcessId(hWnd, R)
return R
End Function
Public Function fnAjoutPossible(ByVal C As Integer(), ByVal S As Integer) As Boolean
Dim B As Boolean = True
Dim i As Integer, L As Integer = C.Length - 1
For i = 0 To L 'Count
If C(i) = S Then
B = False
Exit For
End If
Next
Return B
End Function
Sub New()
ExcelPID = New Integer() {}
ExcelHWnd = New Integer() {}
End Sub
'Sur l'ouverture ou l'obtention de l'objet excel ajoute le code suivant
Dim Id As Integer = fnRecupProcessId(H)
If fnAjoutPossible(ExcelPID, Id) Then
Array.Resize(Of Integer)(ExcelPID, ExcelPID.Length + 1)
ExcelPID(ExcelPID.Length - 1) = Id
End If
'Sur la fermeture tu peux faire comme ça
If Not ExcelApplication Is Nothing Then
ExcelApplication.ActiveWindow.Close()
ExcelApplication.Quit()
End If
Dim N as integer=ExcelPID.Length
For i as integer = 0 To N
Dim localById As Process = Process.GetProcessById(ExcelPID(i))
localById.Kill()
localById.Dispose()
Next
-- Y a autant de bugs dans un programme que de malles-façons dans une maison. Tout dépend de la taille --