Code for closing an Excel object from excel

M

Matt

I have code (see below) to open an Excel file, which contains Excel charts
that are linked to an Access form. I open it because the charts are updated
various times when form is opened, having it open helps response time. I
then have an Access table that is linked to a worksheet from the same Excel
file.

My problem is when I run my exit code, I want the form and Excel object to
close. The code works perfect if I do not use any queries using the linked
Access Table, however if I run a query using the data from the linked access
table, Excel remains open. It apppears the link between Access and Excel is
messing everything up, how can I run a query using a linked table and close
Excel when I exit?

Thanks,
Matt

Private xls As Excel.Application
Private wk As Excel.Workbook

Set xls = New Excel.Application
xls.Visible = False

Set wk = xls.Workbooks.Open("c:Excel.xls", True)

wk.Close False
xls.Quit

Set wk = Nothing
Set xls = Nothing
 
Top