Context Property Example

This example displays the name of the document or template where the macro named "Macro1" is stored.

Set kb = KeysBoundTo(KeyCategory:=wdKeyCategoryMacro, _
    Command:="Macro1")
MsgBox kb.Context.Name

This example adds the F2 key to the Italic command and then uses the For Each...Next loop to display the keys assigned to the Italic command along with the context.

CustomizationContext = NormalTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryCommand, _
    Command:="Italic", KeyCode:=wdKeyF2
For Each oKey In _
        KeysBoundTo(KeyCategory:=wdKeyCategoryCommand, _
        Command:="Italic")
    MsgBox oKey.KeyString & vbCr & oKey.Context.Name
Next