处理后期绑定对象的事件
我想使用 MS Office 自动化并拥有针对用户触发的事件触发的事件处理程序。 例如,如果用户单击Word中的保存按钮,我想拦截该事件并在我的程序中执行代码。
我不想绑定到特定版本的 Word,因为我不知道我的用户将运行哪个版本,因此我使用后期绑定实例化对 Word 的引用。
问题在于 AddHandler 和 Dim WithEvents 命令需要对设计时已知的对象的特定引用。 鉴于此,如何在没有对特定版本的 Word 库的早期绑定引用的情况下定义事件处理程序?
我可以尝试引用早期版本的 Word,并期望新版本的 Word 将向后兼容,但这似乎很笨拙且有风险。
有没有更好的方法而不需要在幕后进行过多的修修补补?
I would like to use MS Office automation and have event handlers that fire for user-triggered events. For example, if the user clicks the save button in Word, I want to intercept that event and execute code in my program.
I don't want to be bound to a specific version of Word because I don't know what version my user will be running, so I instantiate a reference to Word using late binding.
The problem is that the AddHandler and the Dim WithEvents commands require specific references to an object that is known at design time. Given this, how can I define an event handler without having an early bound reference to a specific version of the Word library?
I can try to a reference to an earlier version of Word with the expectation that newer versions of Word will be backwards compatible, but this seems kludgey and risky.
Is there a better way without tinkering too far underneath the covers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像是一个答案,但很难看。 我得再读几遍。
http://www.codeproject.com/KB/cs/zetalatebindingcomevents.aspx
还有更好的选择吗? 我怀疑。 它。
This looks like an answer, but ugly. I'm gonna have to read it a few more times.
http://www.codeproject.com/KB/cs/zetalatebindingcomevents.aspx
Any better options? I doubt. it.
我不认为这是可能的,因为无法保证您所绑定的内容将具有具有相同签名的同名事件。
I don't believe this is possible as there is no way to guarantee what you are binding will have an event of that name with the same signature.