AnsweredAssumed Answered

GetObject(, "Excel.Application") is unreliable, how to fix?

Question asked by Peter Brinkhuis on Dec 10, 2020
Latest reply on Dec 14, 2020 by Peter Brinkhuis

I'm doing some writing to an Excel file from a SolidWorks macro and the hardest part so far is creating a connection to Excel.

 

The approach to connect to an existing Excel application is:

Dim xlApp As Excel.Application

Set xlApp = GetObject(, "Excel.Application")

 

If xlApp is still nothing after this, Excel is apparently not running and you can create a new instance with

Set xlApp = CreateObject("Excel.Application")

I want to avoid this method.

 

The problem is that GetObject is unreliable and I don't understand why. It regularly returns nothing, even when Excel is running. I got it to work on my machine by killing all Excel processes except one, but this method did not work on my client's machine.

 

Any ideas on why this might be happening? This macro will be run on many files using #Task, so I would like to connect to an open Excel file and keep that one open.

Outcomes