Word 2003 KeyBindings Callback Issue to .NET Office Addin. (Correction)

N

NanoWizard

Made a mistake in the C# code:

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

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

Word.WdKeyCategory wdCat = Word.WdKeyCategory.wdKeyCategoryMacro;

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

NanoWizard

Found a work around that was causing the CommandBarButton.State =
Microsoft.Office.Core.MsoButtonState.msoButtonDown even after the
function had been executed.

I am trying to add a KeyBinding to a specific .NET/C# Word Addin
function. I was getting an issue with it unable to bind to the actual
CommandBarButton EventHandler. Therefore, went ahead and set it to
use a VBA procedure which would in-turn call my Addin function.

I reset the state back to what it was previously and set the
ThisDocument.Saved = True. ThisDocument in this context, I am
assuming is the template. Without it, it was prompting the user to
save the template when exiting due to the State change on the button.
Here is the fix:
**********************************************************************
Private Function ExecuteButton(strButtonTag As String) As Boolean
On Error GoTo ExitLabel
ExecuteButton = False

Dim cmdBarControl As CommandBarControl
Set cmdBarControl =
CommandBars.FindControl(Type:=msoControlButton, Tag:=strButtonTag)
If (Not cmdBarControl Is Nothing) Then
Dim oldButtonState as MsoButtonState
oldButtonState = cmdBarControl.State
cmdBarControl.Execute
' Reset the state here so it appears unchanged:
If cmdBarControl.State <> oldButtonState Then
cmdBarControl.State = oldButtonState
ThisDocument.Saved = True
End If
ExecuteButton = True
End If
ExitLabel:

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