如何检测 Excel 是通过自动化启动的(VSTO Addin 上下文) [英] How to dected Excel was starting by automation (VSTO Addin context)

查看:30
本文介绍了如何检测 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 -embedding")

("/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天全站免登陆