Excel Prozess wird nicht im Taskmanager beendet

  • VB.NET

    Excel Prozess wird nicht im Taskmanager beendet

    Hallo,
    ich habe ein Problem bei einem Export von Visual Studio nach Excel.
    Sobald ich mehr als 3 Zellen nach Excel exportiere (ab Zeile 17 bleibt beim Beenden
    der Excel Prozess im Taskmanager hängen. Er geht zwar schon weg
    wenn ich die Form schließe. Aber das stört mich ein wenig.
    Hab auch schon einen Timer eingebunden, hat aber nix geholfen.
    Vielleicht kann mir jemand helfen.

    Was mach ich falsch???

    Gruß Michael



    VB.NET-Quellcode

    1. Sub excel_export()
    2. Dim XLSApp As New Excel.Application
    3. Dim XLSWS As New Excel.Worksheet
    4. Dim path As String = "D:\Kalkulationsblatt.xlsx"
    5. XLSApp.Workbooks.Open(path) : path = Nothing
    6. XLSApp.Visible = True
    7. 'Daten nach Excel schreiben
    8. XLSWS = XLSApp.Sheets(1)
    9. With XLSWS
    10. .Select()
    11. .Visible = True
    12. .Cells(4, 3).value = FRM_VA_KALK.TXT_Kopf_Kunde.Text.ToString
    13. .Cells(6, 3).value = FRM_VA_KALK.TXT_Kopf_Ansprechpartner.Text.ToString
    14. .Cells(8, 3).value = FRM_VA_KALK.TXT_Kopf_Adresse.Text.ToString
    15. .
    16. .
    17. .
    18. End With
    19. XLSWS = Nothing
    20. 'Excel Speichern und beenden
    21. With XLSApp
    22. .ActiveWorkbook.Save()
    23. .DisplayAlerts = False
    24. .Quit()
    25. End With
    26. 'Prozess beenden
    27. System.Runtime.InteropServices.Marshal.ReleaseComObject(XLSWS)
    28. XLSWS = Nothing
    29. System.Runtime.InteropServices.Marshal.ReleaseComObject(XLSApp)
    30. XLSApp = Nothing
    31. GC.Collect()
    32. GC.WaitForPendingFinalizers()
    33. End Sub