Word 2003 KeyBindings Callback Issue to .NET Office Addin.

N

NanoWizard

While this seems like a backward way to do it, it does work.

I am writing a Word 2003 Addin using Visual Studio .NET 2003.
I am adding a keystroke of ALT+Equals, so it calls a function that is
included in the addin called Setup. It works essentially by having
the keybinding bind itself to a VBA macro with the name of
"SetupShortcut" included below, which when called will then execute
the button. This works all fine and good, however, when the function
is executed in this manner the button stays highlighted in a dark
orange color. It takes a second call to deactivate it. Clicking the
button again does not remove it. Has anyone experienced an issue like
this before?


C# Code:
***************************************************************************
object objArg2 = Word.WdKey.wdKeyEquals;
object objMissing = Missing.Value;

// Build the key combination here:
Word.WdKeyCategory wdCat = WordApplication.BuildKeyCode(
Word.WdKey.wdKeyAlt, ref objArg2, ref objMissing, ref objMissing );

// registry the keybinding here:
WordApplication.KeyBindings.Add( wdCat, "SetupShortcut", iKeyCode, ref
objMissing, ref objMissing );
***************************************************************************

VBA Code:
***************************************************************************
There is also a separate .dot file with these methods among others
(not included):
Public Sub SetupShortcut()
ExecuteButton ("SETUP")
End Sub

Private Sub ActivateWindowsDocument()
Application.Activate
If (Application.Documents.Count > 0) Then
ActiveDocument.Activate
End If
' Application.ScreenRefresh
End Sub

Private Function ExecuteButton(strButtonTag As String) As Boolean
On Error GoTo ExitLabel
ExecuteButton = False

Dim cmdBarControl As CommandBarControl
Dim bVisible As Boolean

Debug.Print ("ExecuteButton(" & strButtonTag & ") Called.")
Set cmdBarControl =
CommandBars.FindControl(Type:=msoControlButton, TAG:=strButtonTag)
If (Not cmdBarControl Is Nothing) Then
Debug.Print ("Executing CommandBarControl: " &
cmdBarControl.Caption)
' bVisible = cmdBarControl.Visible
' cmdBarControl.Visible = True
cmdBarControl.Execute
' cmdBarControl.Visible = bVisible
ExecuteButton = True
Debug.Print ("Executed Successfully.")
End If
ExitLabel:
ActivateWindowsDocument
End Function
***************************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top