Hi all, this is driving me crazy. The following routine is called to open a workbook, find two sheets, import them into a table and close the workbook.
Here's the problem, everything works EXCEPT closing Excel. Checking the task manager after this routine exits there is an instance of Excel still running and if I try to open the just closed workbook, I get an error that says it is still in use and open as read-only.
Anybody have any suggestions?
Sub createfile(filename1 As String, account As String)
On Error GoTo Close_Error
foldername = "c:\personal\DEV_MS ACCESS\forecast project\files"
a = foldername & "\" & filename1
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(a)
Set colWorksheets = objWorkbook.Worksheets
'this routine imports the worksheets into tables
For Each objworksheet In colWorksheets
If objworksheet.Visible Then
If objworksheet.Name = "Data Results" Then
DoCmd.TransferSpreadsheet acImport, 8, account & " " & objworksheet.Name, a, False
End If
If objworksheet.Name = "Non-Proforma Revenue" Then
DoCmd.TransferSpreadsheet acImport, 8, account & " " & objworksheet.Name, a, False
End If
End If
Next
'close up everything and exit
objWorkbook.RunAutoMacros xlAutoClose
objWorkbook.Close SaveChanges:=False
Set objWorkbook = Nothing
objExcel.Quit
Set objExcel = Nothing
Exit Sub
Close_Error:
MsgBox Str(Err) & " " & Error()
Resume Next
End Sub
Here's the problem, everything works EXCEPT closing Excel. Checking the task manager after this routine exits there is an instance of Excel still running and if I try to open the just closed workbook, I get an error that says it is still in use and open as read-only.
Anybody have any suggestions?
Sub createfile(filename1 As String, account As String)
On Error GoTo Close_Error
foldername = "c:\personal\DEV_MS ACCESS\forecast project\files"
a = foldername & "\" & filename1
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(a)
Set colWorksheets = objWorkbook.Worksheets
'this routine imports the worksheets into tables
For Each objworksheet In colWorksheets
If objworksheet.Visible Then
If objworksheet.Name = "Data Results" Then
DoCmd.TransferSpreadsheet acImport, 8, account & " " & objworksheet.Name, a, False
End If
If objworksheet.Name = "Non-Proforma Revenue" Then
DoCmd.TransferSpreadsheet acImport, 8, account & " " & objworksheet.Name, a, False
End If
End If
Next
'close up everything and exit
objWorkbook.RunAutoMacros xlAutoClose
objWorkbook.Close SaveChanges:=False
Set objWorkbook = Nothing
objExcel.Quit
Set objExcel = Nothing
Exit Sub
Close_Error:
MsgBox Str(Err) & " " & Error()
Resume Next
End Sub