MS Excel wirklich beenden

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von smitie.

    MS Excel wirklich beenden

    Hallo,

    in meinem Programm greife ich auf Excel zu um dort Daten zu speichern. Mein Problemm, wenn ich den nachfolgendem Code verwende um eine Exel Dateu zu erstellen und zu beenden, wird das Programm Excel lt. Task-Manager nicht geschlossen.

    Wie kann ich Excel wirklich beenden?


    Quellcode

    1. Public Class Form1Private
    2. Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3. 'Sub TestExcel()Dim xlApp As Microsoft.Office.Interop.Excel.Application
    4. Dim xlBook As Microsoft.Office.Interop.Excel.WorkbookDim xlSheet As Microsoft.Office.Interop.Excel.WorksheetxlApp = CType(CreateObject("Excel.Application"), _
    5. Microsoft.Office.Interop.Excel.Application)xlBook = CType(xlApp.Workbooks.Add, _
    6. Microsoft.Office.Interop.Excel.Workbook)xlSheet = CType(xlBook.Worksheets(1), _
    7. Microsoft.Office.Interop.Excel.Worksheet)
    8. ' The following statement puts text in the second row of the sheet.
    9. xlSheet.Cells(2, 2) = "This is column B row 2"
    10. ' The following statement shows the sheet.
    11. xlSheet.Application.Visible = True
    12. ' The following statement saves the sheet to the C:\Test.xls directory.xlSheet.SaveAs("C:\Test.xls")
    13. xlApp.Quit()End Sub
    14. End Class


    Gruß, Rudi
    Hallo Maynard,

    danke für den Hinweis .

    Mit der nachfolgenden Lösung kann man alle laufenden Excel Tasks beenden:

    Quellcode

    1. Dim proc As System.Diagnostics.Process
    2. For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
    3. proc.Kill()
    4. Next

    Gruß, Rudi