Re: Ghostly presence of Excel process



ragtopcaddy via AccessMonster.com wrote in message <5e07eb4a8c7d6@uwe> :
Many thanks (yet again!) to you and Roy,

I've implemented your suggestions, but I'm still having difficulty getting
rid of the Excel process. The Do While loop below is an endless loop. Could
you tell me what's missing?

The following code runs at the end of my StripXLFormats function:

Do While blXLRunning
MsgBox "Excel is still running!!!"
Stop
Set xlObj = GetObject(, "Excel.Application")
xlObj.Quit
Set xlObj = Nothing
blXLRunning = IsExcelRunning
Loop

End Function

The IsExcelRunning function code is below:

Public Function IsExcelRunning() As Boolean
Dim xl As Object

On Error Resume Next

Set xl = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0)

Set xl = Nothing
Err.Clear
End Function


Klatuu wrote:
Without testing all this, I can't be absolutely positive where the problem lies; however, these are some things to consider.

First, this is not uncommon. The problem is caused by incomplete object referencing to your Excel objects. When Access sees an Excel object reference that is not fully qualified, it will create another instance of the Excel process. When you issue the Quit statement, the instance of Excel you created in destroyed, but the one that Access created can still be running. I see one place that is suspect:

Cells.Select
Cells.EntireColumn.AutoFit

These two lines don't explicitly tie the cells to your instance.

That may be why blXLRunning = IsExcelRunning is always true.

Also, I notice that after you call your function StripXLFormats, you open the workbook again but never Quit Excel.

If you did, then the spread*** would disappear. If you want the user to see the spread*** after you have completed it, the better way is to save it, close, quit Excel, then use the Shell function to open it.

The code below runs at the end of a sub that exports queries via a
transferspread*** routine to a new workbook which then has to be formatted, [quoted text clipped - 124 lines] Err.Clear
End Function

My view is to focus on *not* getting an extra instance of excel in the
first place - i e work with the cause of it - not trying to get rid of
it afterwards, which is more like dealing with the symptoms. The link I
gave, should give some hints on that.

For me to be of further assistance, I think I'd like to see the current
code. See also if it makes any difference instantiating with
createobject in stead of with the New keyword, and leave off all that
IsExcelRunning stuff. For instance something along the lines of the
following air code:

on error resume next
Set xlObj = GetObject(, "Excel.Application")
if err.number <> 0 then
' ouch - no instance open, then create one
err.clear
Set xlObj = createobject("Excel.Application")
if err.number <> 0 then
' double-ouch - is excel installed???
exit sub
end if
end if
on error goto <your error handler>

You might perhaps drop in a DoEvents after saving/closing the workbook,
and also after quiting excel?

--
Roy-Vidar


.