I am automating Excel from my application.
My problem is I cannot quit the Excel after the automation process finished!
I checked it still exists on the Process lists and the most DANGEROUS is
everytime the automation function run, it create other Excel and so on. So it
must be out of memory soon.
I have used the app.Quit() method like all the people used but it DOES NOT
work.
What should I do?
Thank you.
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
Ajay
Also, it is not clear if subsequent invocations actualy launch a new version of Excel or
just tack onto the existing executable by putting up another top-level window. In
PowerPoint, I found that Quit() would quit all of PowerPoint, so if I had the sequence
Run My Indexing Program
Indexing Program Launches PowerPoint
Indexing Program finishes processing
Indexing Program Quits PowerPoint
it worked fine, but if I did
Run PowerPoint
Bring up six presentations
Run my indexing program
Indexing program opens document in PowerPoint
Indexing program finishes processing
Indexing program Quits PowerPoint
'
it actually closed the whole of PowerPoint, including all six open presentations.
Furthermore, I decided that if I had already opened the document in PowerPoint and just
wanted to index it after doing some edits, I did not want to actually close it. So my
code now does
If powerpoint is running, set the powerpoint-was-running flag
If the presentation is already open, set the presentatation-already-open flag
Open the document (which, if it is already open, does nothing and returns success)
index it
If the document was not already open, close the document
If powerpoint was not already running, quit powerpoint
Testing it in isolation may give the illusion that Quit() is the right approach, but as I
discovered, it isn't really the correct solution to the problem.
The code to handle this can be found in my PowerPoint Indexer program.
joe
On Wed, 3 Sep 2008 07:13:36 -0700 (PDT), Ajay Kalra <ajay...@yahoo.com> wrote:
>Its very likely that you didnt release the object as Joe suggested.
>Use CComPtr and its variants which will release the object when the
>obejct goes out of scope.
Certainly. But using CCom* is very helpful in most cases. Even if you
use it in the scenario described above, you dont loose anything
compared to not using it.
--
Ajay
So my code is like this:
// Release dispatch pointers.
range.ReleaseDispatch();
sheet.ReleaseDispatch();
sheets.ReleaseDispatch();
book.SetSaved( TRUE );
book.ReleaseDispatch();
book.Close( covTrue, covOptional, covOptional );
books.ReleaseDispatch();
app.Quit();
app.Release(); //threw COleException HERE.
1. Can you please look what do I miss there? If it is possible, can you
please give me the solution by adding / fixing my code above?
I have searched everywhere but I only found the solution in .NET and
JScript. They are totally different with MFC because they have been MANAGED
code so I don't know what to do.
2. How to apply the CComPtr to my code above? Can you please give me the
example of CComPtr using my code above?
3. What is the difference between Release() and ReleaseDispatch()?
Thank you very much.
In some code I have around I use app.ReleaseDispatch(); and it seems
to work...