Close excel leftover by unexpectedly inventor shotdown, How?

Close excel leftover by unexpectedly inventor shotdown, How?

Darkforce_the_ilogic_guy
Advisor Advisor
194 Views
1 Reply
Message 1 of 2

Close excel leftover by unexpectedly inventor shotdown, How?

Darkforce_the_ilogic_guy
Advisor
Advisor

I have some ilogic that use Excel. my problem is that if inventor for some reason fail in the middel of the code .. it migth leave some invisble excel open. and the code fail to run if they stay open .

 

is the a way to get it to close if there is already an excel open by the same name open  ? so that my users don´t need to know they have to use the job liste to close excel before rerun the code again

0 Likes
195 Views
1 Reply
Reply (1)
Message 2 of 2

yan.gauthier
Advocate
Advocate

Put your code in a try catch and close excel if you get an exception ?

 

In my C# addin, I got rid of Excel and use openXml to read and write to excel files (incredibly faster since you don't need to load an excel object in background).

 

OpenXml objects are disposable, so it's easy to handle them in a using block.

 

Otherwise, if you have more than one instance of excel open, Marshal.GetActiveObject(ProgId) will only return the first instance. To find every instance in order to find the one referencing to your workbook, you need to access to the ROT (Running Object Table).

 

Here's a C# example with autocad:

 

https://adndevblog.typepad.com/autocad/2013/12/accessing-com-applications-from-the-running-object-ta...

0 Likes