none
Not Visual Studio, but Visual Basic installed w/ MS Word 2003 RRS feed

  • Question

  • I am trying to execute the following VB code:

       CustomizationContext = ActiveDocument
       KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
        wdKeyY), KeyCategory:=wdKeyCategoryMacro, _
        Command:="DoIt"

    and receive the following error:

    Run-time error '5346': Word cannot change the function of the specified key

    My intent is to assign a "hot-key" within the document.

    What key(s) can I assign, and/or what can I do to enable this to work?

    Thanks in advance for any help you may  be able to provide.

    • Moved by Mike Feng Thursday, December 1, 2011 2:11 PM VBA (From:Visual Basic General)
    Wednesday, November 30, 2011 5:28 AM

Answers

  • Hi John,

     

    Try the following in Module 1 you place the following code:

    Option Explicit
     
    Sub AddHotKey()
        With Application
            .CustomizationContext = ActiveDocument
            .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, wdKeyY), _
            KeyCategory:=wdKeyCategoryCommand, _
            Command:="DoIt"
        End With
    End Sub
    


    Then in Module 2, the following:

    Sub DoIt()
        
        MsgBox "Yup CTR-Y works", vbInformation
        
    End Sub
    

    Tested the above, and it worked very well. :)

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, January 12, 2012 3:48 AM
    Moderator

All replies

  • that's VBA. try asking in the VBA forum:

     

    http://social.msdn.microsoft.com/forums/en/isvvba/threads


    thanks for any help
    • Proposed as answer by Cor Ligthert Wednesday, November 30, 2011 7:25 AM
    • Unproposed as answer by danishaniModerator Wednesday, January 18, 2012 7:24 PM
    Wednesday, November 30, 2011 6:21 AM
  • Or, since it's Microsoft Word, the Word for Developers forum:

    http://social.msdn.microsoft.com/Forums/en/worddev/threads

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, November 30, 2011 2:42 PM
  • Wednesday, November 30, 2011 3:19 PM
  • Hi John,

     

    Try the following in Module 1 you place the following code:

    Option Explicit
     
    Sub AddHotKey()
        With Application
            .CustomizationContext = ActiveDocument
            .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, wdKeyY), _
            KeyCategory:=wdKeyCategoryCommand, _
            Command:="DoIt"
        End With
    End Sub
    


    Then in Module 2, the following:

    Sub DoIt()
        
        MsgBox "Yup CTR-Y works", vbInformation
        
    End Sub
    

    Tested the above, and it worked very well. :)

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, January 12, 2012 3:48 AM
    Moderator
  • thank you for offering your help, can you tell me the address of the vba forum, thank you
    or confirm that the following address is for vba,
     
    --
    isabelle
     
    Le 2011-11-30 01:21, .paul. _ a écrit :
    > that's VBA. try asking in the VBA forum:
    >
    >
    > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    > thanks for any help
     
    Thursday, January 12, 2012 4:35 AM
  • Hi Isabelle,

    Yes, you are welcome and thanks for your contribution as well. :)

     

    I can confirm that you are correct:

    http://social.msdn.microsoft.com/Forums/en-US/isvvba/threads

     

    Is the Visual Basic for Applications (VBA) Forum.

     

     

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, January 12, 2012 5:46 AM
    Moderator
  • hi Daniel,
     
    thank you very much for your answer
    but i do not understand why you direct me to the following address:
    view that we are already here
    look at this image that expresses what i mean : http://cjoint.com/?BAmha2qT5Ip
    perhaps there is a problem with communitybridge.codeplex?
     
    --
    isabelle
      Le 2012-01-12 00:46, danishani a écrit :
    > Hi Isabelle,
    >
    > Yes, you are welcome and thanks for your contribution as well. :)
    >
    > I can confirm that you are correct:
    >
    >
    > Is the Visual Basic for Applications (VBA) Forum.
    >
    > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    > Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
     
    Thursday, January 12, 2012 6:01 AM
  • Hi Isabelle,

     

    I have no idea how the infrastructure is setup, so I need to ask around and see if someone knows.

     

    Best regards,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, January 12, 2012 6:08 AM
    Moderator
  • thank you very much Daniel for your help, i think it will be useful to disentangle this misunderstanding
     --
    isabelle
     
    Le 2012-01-12 01:08, danishani a écrit :
    > Hi Isabelle,
    >
    > I have no idea how the infrastructure is setup, so I need to ask around and see if someone knows.
    >
    > Best regards,
    >
    > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    > Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
     
    Thursday, January 12, 2012 6:25 AM