views:

116

answers:

2

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?

+1  A: 

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.

Velika
thank you so much!
sweeney
A: 

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.

Maslow