So, I want to capture some key commands in our Excel VSTO add-on at the document level. I cannot find a way to do this other than using VBA and talking to VBA. Any help / examples would be appreciated.
I am using Excel 2007.
You can only do this through API calls to subclass Excel and keep track of key commands. This is older, but it still applies.
One method involves using a third-party solution from Addin-Express . Their product includes the ability to add keyboard shortcuts as a property to ribbon menu commands.
Another way is to use low-level keyboard hooks through some Win32 APIs, which are commonly called Windows subclasses. Here is a great explanation with sample code on how to do this. Note that the only "extra" thing you need to do to make this code "work" in VSTO is to move the SetHook() method to the Startup event, and the UnhookWindowsHookEx () method to the Shutdown event.
SetHook()
Startup
Check out the MSDN article here by Stephen Tube.
Finally, there is the use of the OnAction property of the Addin class. This method requires the use of some VBA (from the point of view of the callback method, which points to the base .net add-in), and works fine if you are ready to distribute some VBA in your solution (for example, xls or doc w / VBA Project, or maybe , native addin). Note that you also need to note comvisible = true and provide the GetAutomationServiceObject method GetAutomationServiceObject that your VBA can reference your add-on from VBA code.
OnAction
comvisible = true
GetAutomationServiceObject
look here on the topic ...