Weird Excel Behaviour

G

Guest

Hi all,

I'm having a small issue with Excel after I've run some code in Access 97
and I don't know what the cause of it is. Maybe someone can see what's
causing it.

In code, I create Excel Application, Workbook and Worksheet(2).
I delete and add some sheets.
I then copy values from the results of a SQL string (using recordset) to a
worksheet.
The I create a pivot table and place it in a new worksheet.

After all that it created, I use XlApp.Visible. = True and the workbook
appears in Excel (as a default workbook name, ie Book2). Everything up to
this point works great.

Here's where the issue appears. After I'm all done, and have closed Access
and Excel, if I open another file, Excel opens that file and another blank
workbook (with dfault workbook name), however, it's got the two sheets I
added and it's missing the sheets I deleted (which are the default Shee1,
Sheet2, Sheet3).

And if I open Excel using a shortcut or Programs menu, it opens the regular
blank workbook, with default sheets.

The call to Excel and the remaing code is as follows:
xlApp.Visible = True
Set xlApp = Nothing
Set xlWbk = Nothing
Set xlWshtData = Nothing
Set xlWshtPivot = Nothing

My database and recordsets are all closes before this code. I don't know
what could be causing the problem. Is there something in Excel I've changed?
I'm willing to post the code if anyone needs it to see what I've done.

It doesn't happen on other people's PCs when they open the Access file.

Any help is appreciated, as I'm stuck!

Thanks,
Jay
 
G

Guest

It is very possible you are leaving an instance of Excel running. After your
line:
xlApp.Visible = True
Add:
xlApp.Quit

That will close the instance of Excel you enstanciated when you opened it.
You can determine this by going into Task Manager, selecting the Process tab,
and looking for Excel.exe. The xlApp.Quit will close it. There is one
gotcha with this, however, and that is that you can inadvertantly create an
additional instance of Excel without knowing it. That is caused by incorrect
object referencing. If Access can't associate an object reference to your
xlApp, it will create it's own. If this happens, your Quit will only close
the one you created, and the one Access created will still be running.
 
G

Guest

Ah, that was it. Thanks!

Klatuu said:
It is very possible you are leaving an instance of Excel running. After your
line:
xlApp.Visible = True
Add:
xlApp.Quit

That will close the instance of Excel you enstanciated when you opened it.
You can determine this by going into Task Manager, selecting the Process tab,
and looking for Excel.exe. The xlApp.Quit will close it. There is one
gotcha with this, however, and that is that you can inadvertantly create an
additional instance of Excel without knowing it. That is caused by incorrect
object referencing. If Access can't associate an object reference to your
xlApp, it will create it's own. If this happens, your Quit will only close
the one you created, and the one Access created will still be running.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top