VBA应用程序可以通过COM侦听.NET类库中的事件吗? [英] Can a VBA application Listen for events in a .NET class library through COM?
问题描述
我有一个类库,我在C#.NET。该类有一个公共事件,公共事件EventHandler DataReadyEvent;
是定期触发。
I have a class library that i made in C#.NET. The class has a public event, public event EventHandler DataReadyEvent;
that is triggered periodically.
我有一个VBA应用程序使用 CreateObject(...)
创建此类库的实例。我可以通过COM轻松访问类库的方法和属性,但我似乎不能得到的事件工作。
I have a VBA application that creates an instance of this Class Library using CreateObject(...)
. I can access the methods and properties of the class library easially through COM but I can't seem to get the events to work.
是否可以通过com触发事件?
Is it possible to trigger events through com?
如何在VBA中聆听他们?
How do I listen for them in VBA?
推荐答案
声明一个变量 WithEvents
:
Private WithEvents obj as ObjectType
然后使用编辑窗口下拉菜单先选择 obj
,然后为 obj
的可用事件。它将创建事件处理程序。
Then use the edit window dropdowns to select first the obj
, then available events for the obj
. It'll create event handlers.
这篇关于VBA应用程序可以通过COM侦听.NET类库中的事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!