You can use Application.IgnoreRemoteRequests = true . This will avoid opening excel files in the same Excel process as the one you are using.
However, there is one caveat: you must make sure that all execution paths of your application reset this property to false . This property WILL NOT be reset when exiting and releasing an Excel application, which means that Excel will not correctly respond to the next user who double-clicks the * .xls file, for example.
EDIT: Possible problems with IgnoreRemoteRequest
Well, to make this clearer, Iβll talk a little more about what problems you can use in using this function (at least these are the only ones that I encountered when I had to use this function).
When setting IgnoreRemoteRequests = true you must ensure that you reset this property BEFORE the Excel COM application is missing and / or released. If you do not, Excel will not respond to DDE requests, which means that if someone double-clicks the * .xls file, the file will not open (Excel will start, but it will not open the file automatically).
This, however, is true only if you left the application and / or released it without reselling this property. You just need to make sure that no matter where you are in your code, that you leave / reload, you will set IgnoreRemoteRquests back to false earlier.
If your application crashes and cannot fail (unhandled exception), then the EXCEL process will continue to work (if it is invisible, you will only see it in the task manager). This is normal, since your application did not have the ability to exit and release the internal Excel that it uses. This, however, is not a problem. If the user ignores this βleakedβ Excel process until it is killed on the next reboot or something else, or manually removes it from the taskbar, Excel will work fine.
Note. MS Excel 2007. I do not know about the behavior of previous versions.