M
Mikey B
I am importing multiple Excel 2003 worksheets into my Access 2003 database
with VBA. I want most of the sheets imported in but not the Sheet named
"System" which is always the last tab.
My problem is when I am done I cannot seem to completely close out Excel.
I still see it in the Task Manager.
The first time i run the routine it leaves one instance of Excel when it is
done.
The second time I run the routine it opens a second instance of Excel but
then closes it leaving a bigger first instance of Excel.
The third time I run the routine it locks up Access completely.
I have been trying the ideas I have found on this site and I expect I am not
properly closing out my objects, but have not been able to make anything
work. I am sure it is something obvious I am overlooking, but my eyes are
glazing over and I could use some help.
I am a self taught coder and any help will be greatly appreciated.
this is my code:
Dim objExcel As Object 'Excel.Application
Dim objWorkbook As Object 'Excel.Workbook
Dim objWorksheet As Object 'Worksheet
Dim strFileName As String
Dim strWorksheetName As String
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
strFileName = "C\Test.xls"
Set objWorkbook = objExcel.Workbooks.Open(strFileName)
For Each objWorksheet In objWorkbook.Worksheets
strWorksheetName = objWorksheet.Name
If strWorksheetName = "System" Then
Set objWorksheet = Nothing
objExcel.Workbooks(1).CLose False, , False
Set objWorkbook = Nothing
objExcel.Quit
Set objAccess = Nothing
MsgBox ("Done!")
Exit Sub
End If
DoCmd.TransferSpreadsheet acImport, 8, "tblImportedData",
strFileName, False, strWorksheetName & "!A2:AQ"
Me.Requery
Next
with VBA. I want most of the sheets imported in but not the Sheet named
"System" which is always the last tab.
My problem is when I am done I cannot seem to completely close out Excel.
I still see it in the Task Manager.
The first time i run the routine it leaves one instance of Excel when it is
done.
The second time I run the routine it opens a second instance of Excel but
then closes it leaving a bigger first instance of Excel.
The third time I run the routine it locks up Access completely.
I have been trying the ideas I have found on this site and I expect I am not
properly closing out my objects, but have not been able to make anything
work. I am sure it is something obvious I am overlooking, but my eyes are
glazing over and I could use some help.
I am a self taught coder and any help will be greatly appreciated.
this is my code:
Dim objExcel As Object 'Excel.Application
Dim objWorkbook As Object 'Excel.Workbook
Dim objWorksheet As Object 'Worksheet
Dim strFileName As String
Dim strWorksheetName As String
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
strFileName = "C\Test.xls"
Set objWorkbook = objExcel.Workbooks.Open(strFileName)
For Each objWorksheet In objWorkbook.Worksheets
strWorksheetName = objWorksheet.Name
If strWorksheetName = "System" Then
Set objWorksheet = Nothing
objExcel.Workbooks(1).CLose False, , False
Set objWorkbook = Nothing
objExcel.Quit
Set objAccess = Nothing
MsgBox ("Done!")
Exit Sub
End If
DoCmd.TransferSpreadsheet acImport, 8, "tblImportedData",
strFileName, False, strWorksheetName & "!A2:AQ"
Me.Requery
Next