• Disable short cut keys via .NET code

    Home » Forums » Developers, developers, developers » DevOps Lounge » Disable short cut keys via .NET code

    Author
    Topic
    #462806

    I have used the following code to disable short-cut keys via VB6 Code but the same code does not work in .NET (VSTO) .NET 3.5 SP1

    Excel.Application.OnKey “^{s}” ‘ Ctrl+S Save
    Excel.Application.OnKey “^{x}” ‘ Ctrl+X Cut
    Excel.Application.OnKey “^{c}” ‘ Ctrl+C Copy
    Excel.Application.OnKey “^{v}” ‘ Ctrl+V Paste
    Excel.Application.OnKey “%{F8}” ‘ Alt+F8 Macros…
    Excel.Application.OnKey “%{F11}” ‘ Alt+F11 VBE

    What is different? Oh note that OnKey does not appear via IntelliSense.

    Thank you

    Viewing 0 reply threads
    Author
    Replies
    • #1181102

      If you are doing this in an add-in, then:

      Code:
      Me.Application.OnKey("^{s}", "") ' Ctrl+S Save

      (note: your code was actually re-enabling the shortcut!)

      • #1181110

        If you are doing this in an add-in, then:

        Code:
        Me.Application.OnKey("^{s}", "") ' Ctrl+S Save

        (note: your code was actually re-enabling the shortcut!)

        Thank you Rory. Yea I did figure-out on my own that my sample code was enabling rather than disabling. I just had a blind spot about the need for it being inside () instead of quotes. The code compiled without error and no exceptions were thrown and I am using that as my excuse for being so blind .

        Thank you

    Viewing 0 reply threads
    Reply To: Disable short cut keys via .NET code

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: