Exiting Excel

Alex, over at the Power Shell group in Google talked about Excel not shutting down when told.

Excel is generally the worst offender this way – there have been problems
with it not shutting down when told to that go back a very long time – but
there definitely are other ActiveX applications that exhibit this kind of
behavior. Since ActiveX applications are generally rare and each have their
own quirks, I usually test whether they shut down in different situations
when using them from PowerShell by keeping an eye on the process list, then
release the object if they don’t shut down correctly.
Unfortunately, this isn’t all that useful if you’re keeping an application
around to use during a PowerShell session. In those cases, I’ve noticed that
even some of the better-behaved ActiveX applications don’t work the way we
might want. For example, some of the better-behaved ActiveX applications
will indeed shut down automatically if they don’t have an open, modified
document when you close PowerShell by typing exit, but will hang around if
you close PS with the "X" at the top of the shell window. My general rule of
thumb is to always unhide ActiveX applications and minimize them. This at
least ensures that I can see and close them if I exit PS the wrong way or
lose connection to the app somehow.

One way in Power Shell to kill the process is;

Stop-Process -name EXCEL

Another is to try to release the com object after quiting:

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl) 

Or this;

$xl.quit()

spps -n excel

I am sure that there are others.

Advertisements

One thought on “Exiting Excel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s