Menu

 

Saturday, July 31, 2010

Refernce Collection :-(K) KeyBindings , KeyBound

VBA Code :-

CustomizationContext = NormalTemplate
For Each aKey In KeyBindings
Selection.InsertAfter aKey.Command & vbTab _
& aKey.KeyString & vbCr
Selection.Collapse Direction:=wdCollapseEnd
Next aKey

C# Code :-

public void CustomizationTest()
{
ThisApplication.CustomizationContext = ThisApplication.NormalTemplate;
Word.KeyBindings wordKeyBinding = ThisApplication.KeyBindings;

foreach(Word.KeyBinding wkeybinding in wordKeyBinding)
{
string strText = wkeybinding.Command + " " + wkeybinding.KeyString ;
ThisApplication.Selection.InsertAfter(strText);


object objDir = Word.WdCollapseDirection.wdCollapseEnd ;
ThisApplication.Selection.Collapse(ref objDir);
}
}

VBA Code :-

CustomizationContext = ActiveDocument
KeyBindings.Add KeyCategory:=wdKeyCategoryStyle, _
Command:="Heading 1", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyH)

C# Code :-

public void SpecialKey()
{
ThisApplication.CustomizationContext = ThisApplication.NormalTemplate;
string strCommand = "Heading 1";
Word._Global wrdGlobal = null ;

object wdKeyAlt = Microsoft.Office.Interop.Word.WdKey.wdKeyAlt;
object wdKeyH = Microsoft.Office.Interop.Word.WdKey.wdKeyH;

int keycode = wrdGlobal.BuildKeyCode(Microsoft.Office.Interop.Word.WdKey.wdKeyControl,ref wdKeyAlt,ref wdKeyH, ref missing);


ThisApplication.KeyBindings.Add(Microsoft.Office.Interop.Word.WdKeyCategory.wdKeyCategoryStyle, strCommand, keycode, ref missing, ref missing);
}

VBA Code :-

CustomizationContext = NormalTemplate
For Each myKey In KeysBoundTo(KeyCategory:=wdKeyCategoryCommand, _
Command:="FileNew")
myStr = myStr & myKey.KeyString & vbCr
Next myKey
MsgBox myStr

C# Code :-

public void KeyCatelog()
{
ThisApplication.CustomizationContext = ThisApplication.NormalTemplate;
Word.KeyBindings myKey = ThisApplication.KeyBindings;

foreach (Word.KeyBinding wrdKey in myKey)
{
string mystr = "";
mystr = mystr + wrdKey.KeyString;

}
}

No comments:

Post a Comment