Excel Process not closing in VB.net

后端 未结 8 1074
星月不相逢
星月不相逢 2020-12-03 09:00

I am creating an excel file using interop.excel and the process is not closing. This is the code i am trying to use.

 Private Sub converToExcel(fileLoc As S         


        
相关标签:
8条回答
  • 2020-12-03 09:38

    Finally solved :)

    Private Function useSomeExcel(ByVal Excelfilename As String) 
      Dim objExcel As Excel.Application
      Dim objWorkBook As Excel.Workbook
      Dim objWorkSheets As Excel.Worksheet
    
      Dim datestart As Date = Date.Now
      objExcel = CreateObject("Excel.Application") 'This opens...  
      objWorkBook = objExcel.Workbooks.Open(Excelfilename) ' ... excel process
      Dim dateEnd As Date = Date.Now
      End_Excel_App(datestart, dateEnd) ' This closes excel proces
    End Function
    

    use this method

      Private Sub End_Excel_App(datestart As Date, dateEnd As Date)
        Dim xlp() As Process = Process.GetProcessesByName("EXCEL")
        For Each Process As Process In xlp
         If Process.StartTime >= datestart And Process.StartTime <= dateEnd Then
           Process.Kill()
           Exit For
         End If
        Next
      End Sub
    

    This method closes especific process opened.

    0 讨论(0)
  • 2020-12-03 09:40

    Try System.Runtime.InteropServices.Marshal.FinalReleaseComObject, that should help... also you should call xlWorkBook.Close() and xlapp.quit, if I recall correctly. First call them and then set them to nothing.

    0 讨论(0)
提交回复
热议问题