Dugantrain
I Love Pants
- Local time
- Today, 05:22
- Joined
- Mar 28, 2002
- Messages
- 221
I have the following code which opens an Excel workbook,
Refreshes the Excel worksheets which query a ProTrack
database, transfers the data in Access, and then closes the
workbook and cleans up after itself:
Two small things are bugging me:
1. It prompts the user to Save before closing the workbook
2. I would think that the Excel object has been completely
released, but after closing the file, I keep getting a
message saying that the Excel file is "Available For Editing".
How can I omit these two things?
Refreshes the Excel worksheets which query a ProTrack
database, transfers the data in Access, and then closes the
workbook and cleans up after itself:
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"
Set xlWB = xlApp.Workbooks.Open(strFile)
xlApp.Visible = True
xlApp.ActiveWorkbook.RefreshAll
xlApp.Visible = False
For Each xlWS In xlWB.Worksheets
DoCmd.TransferSpreadsheet acImport, , "tblCAD_Import", strFile, True, xlWS.Name & "!"
Next
xlWB.Close
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
Two small things are bugging me:
1. It prompts the user to Save before closing the workbook
2. I would think that the Excel object has been completely
released, but after closing the file, I keep getting a
message saying that the Excel file is "Available For Editing".
How can I omit these two things?