none
Programatically assign a subroutine to a function key? RRS feed

  • Question

  • I know how to manually assign a function key to one of my subroutines.  Is there a way to programatically do this same function (with VBA code)?

    BTW, I tried running the "Record macro" function and then I tried to manually assign one of my subroutines to the F3 key.  Here is the code that Word VBA generated:

      KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF3), KeyCategory:= _
        wdKeyCategoryCommand, Command:=""
    

    I tried to assign the F3 key to a subroutine named "MyCode", but I don't see any references to my subroutine.  So, I'm still confused about how to programatically assign a function key to one my subroutines.  Any tips?

    Robert

     


    jmmc
    Friday, May 13, 2011 11:50 AM

Answers

  • Hi Robert,

    Make it look like this:

        KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, Command:="DisplayHelp", KeyCode:=wdKeyF1

    In the above example the F1 key is bound to the public sub DisplayHelp.

    Hope this helps


    Regards, Rich
    Friday, May 13, 2011 12:45 PM

All replies

  • Hi Robert,

    Make it look like this:

        KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, Command:="DisplayHelp", KeyCode:=wdKeyF1

    In the above example the F1 key is bound to the public sub DisplayHelp.

    Hope this helps


    Regards, Rich
    Friday, May 13, 2011 12:45 PM
  • PS - I should have added to set the context also.

        CustomizationContext = ActiveDocument


    Regards, Rich
    Friday, May 13, 2011 12:48 PM