Hi,
I am using the following code to open an existing Excel file and saving it as different format.
However the Excel.exe process is not closing...
Imports Microsoft.Office.Interop
Dim strPath As String
Dim strFile As String
Dim strExtension As String
Dim strPathFile As String
strPath = "c:\test\"
strFile = "test"
strExtension = ".xls"
strPathFile = strPath + strFile + strExtension
Try
Dim xlApp = New Excel.Application
xlApp.Application.DisplayAlerts = False
Dim xlWorkBooks As Excel.Workbooks = xlApp.Workbooks
Dim xlWorkBook As Excel.Workbook = xlWorkBooks.Open(strPathFile, System.Reflection.Missing.Value, System.Reflection.Missing.Value, _
System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, _
System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, _
System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, _
System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value)
Dim xlSheets As Excel.Sheets = xlWorkBook.Sheets
Dim xlWorkSheet As Excel.Worksheet = xlSheets(1)
strFile = "test2"
strPathFile = strPath + strFile + strExtension
xlWorkSheet.SaveAs(strPathFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8, Type.Missing, Type.Missing, False, False, _
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, _
Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing)
MsgBox("open")
xlWorkBook.Close()
xlWorkBooks.Close()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBooks)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
Catch ex As Exception
MsgBox("error")
End Try
Open in new window