On Error Close Excel

jdp0412

New Member
Joined
Sep 28, 2005
Messages
25
I'm using an access database that gathers information from an external program it then takes the gathered information and outputs to an excel file
Sometimes this generates an error (error talking between access and other application) and since I have the excel workbook created close to the start of the routine and have it hidden I want to close the Excel application, currently I use this code

objxlapp.ActiveWorkbook.Saved = True
objxlapp.Quit
(where objxlapp is the excel application)

This code works just fine most of the time...
Sometimes it is not the communicating between access and other program that generates the error, sometimes a user forgets to input some required information into a form. When this happens the Excel appliaction has not been started and there is nothing to end, thus generating another error. Anyone have any ideas as to check and see if the Excel process is running and if so end it?
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
jdp0412

Try, objxlapp.Close, inplace of objxlapp.Quit.

Datsmart
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Correction:

Use objxlapp.Close,
then your code of objxlapp.Quit.

I believe you will need both.
 

jdp0412

New Member
Joined
Sep 28, 2005
Messages
25
The object has not yet been created so I still causes the same problem

Set objxlapp = CreateObject("excel.application")

If it has not gotten to that place in the code there is no such thing as "objxlapp" so even trying to use

Well I think for the moment I will try this....

Code:
Function Exists(name)
 On Error GoTo doesnotexist
 name.close
 exists = True
Exit Function
 doesnotexist:
  exists = False
End function
Then in the error handling section of the routine put
Code:
If exists(objxlapp) = True Then
objxlapp.Quit
End if
Any other suggestions as how to accomplish this?
 

jdp0412

New Member
Joined
Sep 28, 2005
Messages
25
Actually that method does not work either, still getting an error from the
objxlapp.close


Not sure hot to fix this....
 

Forum statistics

Threads
1,077,782
Messages
5,336,295
Members
399,074
Latest member
rlong98

Some videos you may like

This Week's Hot Topics

Top