Try the answers given here:
http://social.msdn.microsoft.com/For...-excel-problem
Basically, you may be doing something that leaves an object unclosed and when you set the ExcelApp to Nothing, Excel does not go away. Since you declared ExcelWorkBook also, you must set it to Nothing also.
Maybe try something like:
'DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "StockData", MyPath, True
'************************************************* ************
Debug.Print ExcelWorkBook.Name
If Not (ExcelWorkBook Is Nothing) Then
ExcelWorkBook.Close
Set ExcelWorkBook = Nothing
End If
If Not (ExcelApp Is Nothing) Then
ExcelApp.Quit 'this line terminates the process
Set ExcelApp = Nothing
End If
MsgBox "Done"
Exit function
ErrorTrap:
Debug.Print "(" & Err.Number & ") " & Err.Description
If Not (ExcelWorkBook Is Nothing) Then
ExcelWorkBook.Close
Set ExcelWorkBook = Nothing
End If
If Not (ExcelApp Is Nothing) Then
ExcelApp.Quit 'this line terminates the process
Set ExcelApp = Nothing
End If