I have reviewed many of the references to openning and using an Excel spreadsheet from VB6 within this forum, but am still not able to fix the following problem:
I am reading between 100 and 35,000 lines from various Excel spreadsheets and am writing the spreadsheet data to a single Access table. For most spreadsheets, the application is working as planned (reading, writing and closing Excel). For larger spreadsheets (approximately 20,000 lines and above), all of the data is being properly read and written, however the closing of the Excel application is not occurring (I can see the Excel process remaining). I cannot seem to make this process go away (programmatically).
If I try to run this application again, it attempts to start a new occurance of Excel and then 'hangs' the application. I must then manually stop the processes for the main application and the two instances of Excel before I can successfully run the application again.
Below is the main portion of my code.
Thanks in advance for any Help you can provide!
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
'
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application"
If Err Then
Err.Clear
Set xlApp = Nothing
Set xlApp = CreateObject("Excel.Application"
If Err <> 0 Then
MsgBox "Unable to Read Spreadsheet Data", & _
vbExclamation & vbOKOnly, _
"Data Import Unavailable"
End
End If
End If
'
Set wb = xlApp.Workbooks.Open(txtFileName.Text)
Set ws = wb.Worksheets(1)
'
For Idx = 1 To LastRow
SSN = ws.Range(A & Idx).Value
LName = UCase(ws.Range(B & Idx).Value)
FName = UCase(ws.Range(C & Idx).Value)
DOB = ws.Range(D & Idx).Value
SqlString = "Insert into DEMOGRAPHICS(SSN," & _
"LastName,FirstName,BirthDate) " & _
"VALUES (SSN,LName,FName,DOB)"
oConn.Execute (SqlString)
ProgressBar1.Value = Idx
Next Idx
'
' Clean up spreadsheet objects
'
wb.Close
xlApp.Quit
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
I am reading between 100 and 35,000 lines from various Excel spreadsheets and am writing the spreadsheet data to a single Access table. For most spreadsheets, the application is working as planned (reading, writing and closing Excel). For larger spreadsheets (approximately 20,000 lines and above), all of the data is being properly read and written, however the closing of the Excel application is not occurring (I can see the Excel process remaining). I cannot seem to make this process go away (programmatically).
If I try to run this application again, it attempts to start a new occurance of Excel and then 'hangs' the application. I must then manually stop the processes for the main application and the two instances of Excel before I can successfully run the application again.
Below is the main portion of my code.
Thanks in advance for any Help you can provide!
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
'
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application"
If Err Then
Err.Clear
Set xlApp = Nothing
Set xlApp = CreateObject("Excel.Application"
If Err <> 0 Then
MsgBox "Unable to Read Spreadsheet Data", & _
vbExclamation & vbOKOnly, _
"Data Import Unavailable"
End
End If
End If
'
Set wb = xlApp.Workbooks.Open(txtFileName.Text)
Set ws = wb.Worksheets(1)
'
For Idx = 1 To LastRow
SSN = ws.Range(A & Idx).Value
LName = UCase(ws.Range(B & Idx).Value)
FName = UCase(ws.Range(C & Idx).Value)
DOB = ws.Range(D & Idx).Value
SqlString = "Insert into DEMOGRAPHICS(SSN," & _
"LastName,FirstName,BirthDate) " & _
"VALUES (SSN,LName,FName,DOB)"
oConn.Execute (SqlString)
ProgressBar1.Value = Idx
Next Idx
'
' Clean up spreadsheet objects
'
wb.Close
xlApp.Quit
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing