如何通过自动方式启动Excel(VSTO Addin上下文) [英] How to dected Excel was starting by automation (VSTO Addin context)

查看:382
本文介绍了如何通过自动方式启动Excel(VSTO Addin上下文)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

我正在运行VSTO Excel应用程序上下文加载项,并且当其他进程在可见模式下自动启动MS Excel时,也会加载我的加载项.

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.

所以现在,有必要知道MS Excel是否是由另一个具有自动化功能的进程启动的,例如

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

  • CreateObject()
  • ExcelApplicatoin.Visible = true

("/automation -embeddding")

("/automation -embedding")

目前,我评估以下Excel属性:

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

ThisAddIn.Application.UserControl

但是在CreateObject期间启动MS Excel时,该属性始终为"False".

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.

推荐答案

我认为可以使用cmd参数:

I think cmd arguments can be used:

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

这篇关于如何通过自动方式启动Excel(VSTO Addin上下文)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆