Sukram
Sukram

Reputation: 37

How to dected Excel was starting by automation (VSTO Addin context)

Context:

I'm running a VSTO Excel application context addin and I will load my addin also when MS Excel was started by an other process for automation in visible mode.

So now, it's necessary to know if MS Excel was started by an other process with automation e.g

("/automation -embedding")

At the the moment, I evaluate the following Excel Property:

ThisAddIn.Application.UserControl

But when MS Excel is started during CreateObject the property is alsways "False".

Does have anyone any idea to solve this problem? I have no other properties found to solve this problem.

Upvotes: 2

Views: 1818

Answers (1)

mkhrapunov
mkhrapunov

Reputation: 46

I think cmd arguments can be used:

bool isExcelStartedByAutomation = (Environment.GetCommandLineArgs().Contains("/automation") && Environment.GetCommandLineArgs().Contains("-Embedding"));

Upvotes: 2

Related Questions