Okay so my program opens excel, reads a few cells, and closes excel. But, it does not fully close excel and after multiple runs, I have multiple EXCEL.EXE *32 in my process list. It also asks for a save when it's closing when there are no changes being made, is there any way to avoid this? And how do you get Excel to fully close?
Imports Excel = Microsoft.Office.Interop.Excel
vb Code:
Public Sub XLMain() xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook = xlApp.Workbooks.Open(strExcelPath) xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet) 'Stuffs to be did ReadXL() ImportXL() 'Close Excel: CloseExcel() End Sub Public Sub CloseExcel() xlBook.Close() xlApp.Quit() End Sub Public Sub ReadXL() Try ordernumber = xlSheet.Cells(5, "C").Value.ToString owner1 = xlSheet.Cells(6, "C").Value.ToString county = xlSheet.Cells(6, "I").Value.ToString fulladdress = xlSheet.Cells(7, "C").Value.ToString address = Mid(fulladdress, 1, InStr(fulladdress, ",") - 1) halfaddress = Mid(fulladdress, address.Length + 2) zip = Mid(fulladdress, fulladdress.Length - 4, 5) city = Mid(halfaddress, 1, InStr(halfaddress, ",") - 1) state = Mid(fulladdress, address.Length + city.Length + 4, 2) Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
I also just tried this, and it did not work:
vb Code:
Public Sub CloseExcel() 'xlBook.Close() 'xlApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) GC.Collect() End Sub
Just tried this also, and it did not work:
The program closes, without asking for a save, gets me the data I need, but remains in the process list.vb Code:
Dim strExcelPath As String = "C:\Users\Aj\Desktop\Tax_Research_Template_2010_-_Excel.xls" Dim xlApp = New Excel.Application() Dim xlWbs = xlApp.Workbooks Dim xlBook = xlWbs.Open(strExcelPath) Dim xlSheet = xlBook.Worksheets(1) Public Sub CloseExcel() xlBook.Close() xlApp.Quit() xlBook = Nothing xlWbs = Nothing xlApp = Nothing End Sub
Using this for my Imports
Code:Imports Excel = Microsoft.Office.Interop.Excel




Reply With Quote