Re: [RESOLVED] Closing Excel
My excel refuses to close again after the changes I had to make in order to have my .DLL work properly with a parent form:
vb Code:
Dim strExcelPath As String
Dim xlBook As Excel.Workbook
Dim xlWbs As Excel.Workbooks
Dim accConn = New OleDbConnection
#Region "properties"
Public Property ExcelPath() As String
Get
Return strExcelPath
End Get
Set(ByVal value As String)
strExcelPath = value
xlBook = xlWbs.Open(strExcelPath)
End Set
End Property
Public Property AccessConn() As OleDbConnection
Get
Return accConn
End Get
Set(ByVal value As OleDbConnection)
accConn = value
End Set
End Property
#End Region
Public Sub XLMain()
ReadXL()
ImportXL()
End Sub
'Functions/Subs
Public Sub ReadXL()
Dim xlApp = New Excel.Application
xlWbs = xlApp.Workbooks
Dim xlSheet = xlBook.Worksheets(1)
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
xlBook.Close()
xlApp.Quit()
xlApp = Nothing
xlWbs = Nothing
xlBook = Nothing
xlSheet = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Public Sub ImportXL()
Dim cmdInsert As New OleDbCommand("INSERT INTO Orders (OrderNumber, Owner1Full, County, City, State, Address, ZipCode) VALUES ('" & ordernumber & "', '" & owner1 & "', '" & county & "', '" & city & "', '" & state & "', '" & address & "', '" & zip & "')", accConn)
accConn.Open()
Try
cmdInsert.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox(ex.ToString)
End Try
accConn.Close()
End Sub
End Class
It is back to closing EXCEL.EXE when the parent Form closes. Which is unacceptable as this will be a service running 24/7
Re: [RESOLVED] Closing Excel
vb Code:
Public Sub callstuff()
tempExcel.AccessConn = accConn
tempExcel.ExcelPath = "C:\Users\Aj\Desktop\Tax_Research_Template_2010_-_Excel.xls"
tempExcel.XLMain()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Fixed.