Force Excel to close

N

Nigel

I am running some automated reports and using a batch file to run them in
sequence, one issue I am having is forcing each report to close after it is
complete, the command I am using is

application.quit but this seems to be very flaky, is there a better way to
force excel to close when the report is complete

thanks
 
J

JLGWhiz

Application.Quit is the appropriate method of closing the application.
However, certain protocol should be followed in using it. Be sure that all
files for that instance of the application are closed before before
executing the Quit command. To avoid error or run time messages, when
closing the files, establish their saved status. Either save them, use the
Saved = True or SaveChanges = False to avoid the messages. A review of the
VBA help file on these topics might provide additional assistance.
 
N

Nigel

I have this at the end of the code

ThisWorkbook.Save
application.Quit

the workbook is saving but excel is not closing,

if I do this

thisworkbook.save
thisworkbook.close

and then on the before close event

application.quit

it seems to work fine
 
J

Joel

Do you have more than one workbook Opened?

Nigel said:
I have this at the end of the code

ThisWorkbook.Save
application.Quit

the workbook is saving but excel is not closing,

if I do this

thisworkbook.save
thisworkbook.close

and then on the before close event

application.quit

it seems to work fine
 
J

Joel

Check you task maanger to make sure you don't have more than one workbook
opened. Is the batch file calling each batch file and there is a workbook
open event so the macro in each workbook atumatically runs.

The close will close the workbook and automatically stop the macro because
the macro is part of the workbook that was closed leaving the application
open. if you are saving the workbook then you don't want to close the
workbook becasue the excel application will be left open. Instead just
perform the quit which wil also close the workbook.
 

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