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?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Correction:

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

I believe you will need both.
 
Upvote 0
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?
 
Upvote 0
Actually that method does not work either, still getting an error from the
objxlapp.close


Not sure hot to fix this....
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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
Back
Top