Hi Rob,
I knew what you meant, and what you want. But I don't think
you can do it (in this version of VSTO). I was listing what
is possible with keyboard shortcuts.
As I recall from discussions during VSTO beta, I think you
need something called a "callback", and if I understood
correctly, this means you have to have some VBA code in the
Word environment, somewhere. Here's an example (for Excel,
but same principle):
--
Here's an example for you that illustrates with the OnKey...
1. Create a new workbook and put the following code in a
module:
Dim managedObject As Object
Public Sub RegisterCallback(callback As Object)
Set managedObject = callback
Application.OnKey "^m", "DoManagedCallBack"
End Sub
Public Sub DoManagedCallBack()
managedObject.HandleCtrlM
End Sub
2. Then, create a new Excel project based on the existing
workbook you created.
3. Add the following code to the project:
Private Sub ThisWorkbook_Open() Handles ThisWorkbook.Open
ThisApplication.Run("RegisterCallback", Me)
End Sub
Public Sub HandleCtrlM()
MsgBox("HandleCtrlM")
End Sub
4. Press F5 to run; when you press Ctrl+m in Excel, the
DoManagedCallBack routine in the assembly is run.
So, what's happening here is that a) you call a macro in the
workbook to pass it a reference to the assembly's class, b)
the macro stores the reference to the object, c) you set up
OnKey to call a macro in the workbook, and d) when the
"OnKey" routine fires, it will use the stored reference to
the object to call a public method (HandleCtrlM in this
example) in the assembly code. Of course, for this to work,
the VBA security settings must allow the VBA code in the
workbook to run.
--
But you may want to ask for more details in the
vsnet.vstools.office newsgroup, where an occasional person
from MSFT drops by
Thanks Cindy, but I don't think that's quite what I meant.
I don't want to use VBA code for the shortcuts. I have
already converted the VBA to C#. How can I assign a
shortcut key to the C# code? The Word UI doesn't seem to
allow it - all it allows is assigning to VBA code, and I
haven't had any luck doing it programmatically using
KeyBindings (see original post).
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word
This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail