Close Excel

D

Dennis Cheung

I try the following module to close the Excel, but it didn't work. I am using
a simplified Chinses version, does it make any difference? It is a module I
found in here.

Public Function CloseMyExcel()
Excel.Application.Quit
End Function
 
K

Ken Snell [MVP]

It depends upon how you opened EXCEL in the first place. Please provide more
details about what you're doing.
 
D

Dennis Cheung

There are few situiations.
1 Opened by the Macro, runapp, in Access.
2 Opened by activited the application.
3 Run the module but EXCEL is not opened.

One more question, can this module apply to a macro in EXCEL? I want to
build a Macro to close EXCEL in EXCEL.

Thanks for your reply.
 
K

Ken Snell [MVP]

The function that you're trying to use will not work unless your database
file has a reference set to the specific EXCEL library. And even then, I
don't believe it will work unless you have opened EXCEL via VBA code
(Automation), where you have created the object in the code.

My own quick testing shows that it won't work if you open EXCEL via RunApp
macro action, and then try to run this function (even if you set the EXCEL
library to be part of the database's references). Nor does it work if you
open EXCEL yourself (outside the database).

If you run the function and EXCEL is not open, nothing will happen (no
errors, etc.).

It's possible to have an EXCEL macro close the EXCEL application. And it's
possible for that EXCEL macro to be run from ACCESS, but only via VBA code
(not by a macro).
--

Ken Snell
<MS ACCESS MVP>
 
D

Dennis Cheung

Thanks ken!

Can you help me to write a macro in EXCEL to close EXCEL application?
 
K

Ken Snell [MVP]

It's essentially the same as what you posted:

Public Sub CloseExcel()
' This macro is for EXCEL, not for ACCESS
Application.Quit
End Sub
 

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