Closing Excel 2000 from VB (Unwanted process EXCEL.EXE)

S

Simon C

I have an Access database - it uses the following code to open Excel

Public Sub OpenXlSheet(strReportName As String)
' Check if excel is open, close it if it is
If AppInUse("xlmain") <> 0 Then
Dim objExcel As Excel.Application
Set objExcel = GetObject(, "Excel.Application")
objExcel.Quit
Set objExcel = Nothing
Do While AppInUse("xlmain") <> 0
Loop
End If
'open a fresh excel application and load strReportName

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Visible = True
objExcel.Workbooks.Open strReportName, , True
Set objExcel = Nothing

End Sub


The excel sheet opened is then closed from a userform with the
Application.Quit command

Everything appears to work corectly but it leaves an EXCEL.EXE process
behind and the next time I try and run excel from Access it gets caught
in that loop recognising that theres an excel app running but unable to
close it

Any ideas why this happens or how I get rid of the rogue process?

Thanks in advance

Simon
 
E

Ed

I'm not the sharpest knife in the drawer in this stuff, Simon, but I
wonder - you don't say if the UserForm that closes Excel is in Access or
Excel. If it's in Access, then it must have an object handle somewhere - is
that object properly terminated? If it's an Excel UserForm, I have doubts
about a UserForm being able to terminate the application that's allowing it
to exist.

The other thing to remember is that *every* time you instance Excel, you
MUST terminate the app (if this is what you want to do), NOT just terminate
the object. Of course, you wouldn't terminate until you're done with the
file! But I've given myself more than one headache by calling files and
then closing them, but failing to shut down the app when I was done.

You might want to print out your code blocks and highlight every time you
call Excel, and then search for your termination. Or step through
everything and watch the Locals window to see if the app is terminated when
you expect it to be. (I know in Word and Excel - I would assume Access
also - you can put Stop in your code and it will flip you into the VBE so
you don't have to F8 through a long process.) You might also want to make
sure AppInUse (which you didn't post) is actually grabbing the Excel app -
if not, why not?

HTH
Ed
 
A

aaron.kempf

i think that you can use a command line kill.exe i thnk that it's a
part of the Win2k resource kit; but i thoguht that it was available by
default in XP and 2003

i dont know

go to freevbcode.com and look for the word process
 
A

aaron.kempf

i think that you can use a command line kill.exe i thnk that it's a
part of the Win2k resource kit; but i thoguht that it was available by
default in XP and 2003

i dont know

go to freevbcode.com and look for the word process
 
S

Simon C

Thanks for the ideas all,

Ed I think you were along the right lines with your idea about the
userform...

The Excel UserForm (thats used to terminate Excel) doesn't 'close
properly' along with the rest of Excel when the Application.Quit
command is used.

Adding the line UserForm.Hide before Application.Quit seems to have
solved the problem
 

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