Excel Automation Message Avoidance

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:
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?
 
For question 1:
Change
xlWB.Close
to
xlWB.Close SaveChanges:=False
 
Yes, thank you, that actually took care of both problems as far as the messages. However, even though my code reads like I have destroyed the Excel object, the Spreadsheet is still hanging around in the background. Anyone have any ideas why it would be doing that?
 

Users who are viewing this thread

Back
Top Bottom