Dugantrain
Active Member
- Joined
- Feb 10, 2003
- Messages
- 354
I have the following code in Access which successfully has an Excel Workbook Refresh its queries from another Data Source (a ProTrack database) and then imports that data from Excel into Access:
The problem is that the Excel workbook seems to still be hanging around in the background, even though I have closed the Workbook as well as quit the Excel application and released all variables. Also, when I try to open any other workbook, I get a ghost frame of that workbook and can only get Excel to function properly again when I do a Ctl-Alt_Del and manually end Excel. Could there be something in the above code that is doing this, it certainly seems fine enough.
Code:
Public Function XL_CAD_Routine()
On Error GoTo XL_Cad_Routine_Err
Dim strFile As String
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
Dim xlApp As New Excel.Application
strFile = "S:\WAMU-XP\Scheduling_Database\BRIO_CADs\Protrack_CADs.xls"
Forms!FrmScheduling.Form!LblCad_Import_Status.Caption = "Locating Excel File..."
DoEvents
Set xlWB = xlApp.Workbooks.Open(strFile)
Forms!FrmScheduling.Form!LblCad_Import_Status.Caption = "Requerying Data Source..."
DoEvents
xlApp.Visible = True
xlApp.ActiveWorkbook.RefreshAll
xlApp.Visible = False
DoEvents
Forms!FrmScheduling.Form!LblCad_Import_Status.Caption = "Importing Data..."
DoEvents
For Each xlWS In xlWB.Worksheets
xlWS.Select
xlWS.Range("S1").Select
ActiveCell = "STATUS"
DoCmd.TransferSpreadsheet acImport, , "tblCAD_Import", strFile, True, xlWS.Name & "!"
Next
Forms!FrmScheduling.Form!LblCad_Import_Status.Caption = "Closing Excel..."
DoEvents
xlWB.Close False, strFile
xlApp.Quit
Set xlWS = Nothing
Set xlWB = Nothing
Set xlApp = Nothing
Exit Function
XL_Cad_Routine_Err:
MsgBox "XL_CAD_Routine: " & Err.Description
Exit Function
End Function