So I found 1 great article that looked promising but it didn’t pan out because it was written before a change by Excel. Basically the problem is that GetObject (or c# GetActiveObject) only gets a RANDOM copy of a running instance. If there is more than one instance of Excel, for instance, and you are searching for a workbook (in my case one with a specific named range) you will not find the workbook unless you iterate through all the Application instances of Excel. If you look in Task Manager … why are there two? Simple. If you are in explorer and you click on a .xls* file and the preview pane is on – it starts an instance of Excel (one example).
Here is the article that did not work and here is a complicated one that is just as good as the GetObject (it gets only once instance) … HOWEVER … combining the two … now that is magic. I got it working. This article is a sub-article of the last post in which I iterated over all apps searching for a .visible instance in which to piggy back and run VBA the code in Excel. Why? Because I had LOTS of previous code already written in Excel – I just needed it to run. It starts and drives AutoCAD. Continue reading