从VBA访问VSTO应用程序插件类型(EXCEL) [英] Accessing a VSTO application-addin types from VBA (Excel)

查看:289
本文介绍了从VBA访问VSTO应用程序插件类型(EXCEL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Excel的VSTO应用程序插件(不是文档插件),我们要对事件暴露给VBA代码,以便VBA宏可以做一些动作时,在插件此事件。我怎样才能获得VBA代码,以便能够订阅的VSTO应用程序插件定义的事件?

We have a VSTO application-addin (not a document-addin) for Excel, and we want to expose an event to VBA code so that the VBA macro can do some action when this event fires in the addin. How can I get the VBA code to be able to subscribe to an event defined in the VSTO application-addin?

我倒是觉得,既然插件在加载Excel进程,这不应该是太棘手,但还没有找到一种方法呢。

I'd think that since the addin is loaded in the Excel process, this shouldn't be too tricky, but haven't found a way yet.

BTW,使用VS 2008和Excel 2007。

BTW, using VS 2008 and Excel 2007.

谢谢!

推荐答案

VSTO不是说一般可以从其他DLL调用的DLL。 VSTO基本上是COM暴露的.NET代码从一个单独的AppDomain中操作的包装内运行。虽然你的VSTO加载项是技术上的加载到Excel中的一个DLL,它的运作更像是一个顶级的EXE,而不是暴露给其他呼叫者一个DLL库。

VSTO is not a DLL that can generally be called from other DLLs. VSTO is basically COM-exposed .NET code operating from within a wrapper operating from within a separate AppDomain. Although your VSTO add-in is technically a DLL that is being loaded into Excel, it operates more like a top-level EXE rather than as a DLL library exposed to other callers.

就个人而言,我会创建一个标准的.NET程序集 - 也就是说,避免使用VSTO本 - 并使用正确的属性将其暴露在COM。这个过程很好了说明: COM互操作暴露 - 第2部分,在题为揭露.NET活动的部分COM。

Personally, I would create a standard .NET assembly -- that is, avoid using VSTO for this -- and expose it to COM using the correct attributes. The process is well explained here: COM Interop Exposed - Part 2, under the section titled "Exposing .NET Events to COM".

如果你真的坚持使VBA来能够调用VSTO,那么你就必须通过 Office.COMAddIn操作.Object 这是通过覆盖 RequestComAddInAutomationService 方法enabled属性。该方法详细的文章 VSTO讨论加载项,COMAddIns和RequestComAddInAutomationService 通过安德鲁白教堂。

If you really insist on enabling VBA to be able to call VSTO, then you'll have to operate via the Office.COMAddIn.Object property which is enabled by overriding the RequestComAddInAutomationService method. The process is discussed in detail in the article VSTO Add-ins, COMAddIns and RequestComAddInAutomationService by Andrew Whitechapel.

我希望这有助于!

迈克

这篇关于从VBA访问VSTO应用程序插件类型(EXCEL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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