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?
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

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....
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,329
Members
414,055
Latest member
mcarduner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top