none
Excel addin disable ALT + E (move or copy sheet) RRS feed

  • Question

  • Hello Support Team,

    I'm developing Excel add-in by C# and need to disable Move or Copy Sheet.

    I have added Ribbon custom UI to disable from menu like bellow, and the menu Move Or Copy was disabled. But when I use keyboard shortcuts ALT + E then M, it's still enable to Move or Copy  sheet.

    <command idMso="SheetMoveOrCopy" getEnabled="GetEnabled"/>

    I checked the document here https://msdn.microsoft.com/en-us/library/office/ff197461.aspx and It said I can use Application.OnKey function to disable shortcuts, so I tried to disable ALT + E as bellow code. This code will run when WorkbookActivate event trigger

    Application.OnKey("%e", "");

    But it does not work. I used to try with other shortcuts like Application.OnKey("{F12}", ""); and it works, but not sure why with "%e" it does not. Do you have any idea how to solve this problem?

    Thank you for your support.

    Johnny






    • Edited by Johnny-Le Wednesday, April 13, 2016 11:01 AM
    Wednesday, April 13, 2016 10:50 AM

Answers

All replies

  • Hello Johnny,

    You need to set a keyboard hook, see Using shortcut keys to call a function in an Office Add-in for the sample code.

    The SetWindowsHookEx method installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events.


    [custom.development]

    • Marked as answer by Johnny-Le Thursday, April 14, 2016 8:52 AM
    Wednesday, April 13, 2016 2:48 PM
  • Hi, Johnny

    You are using

    Application.OnKey("%e", "");

    And its not working.

    When you type Alt + E manually in Excel  at that time a ToolTip appears over the ribbon, indicating which letters you have typed so far and When you have entered enough letters, the command is invoked. . If you have forgotten the sequence, you can press Esc to exit the Excel Access Key mode.

    So here just Alt + E is not a full shortcut key. It also have many options that you can use after pressing Alt+E.

    Like here your full short cut key is Alt + E+ M. so Excel waits for you to press option like that.

    So if you want to disable it. You have to specify full shortcut that is belonging to move or copy sheet.

    But here Application.onkey() doesn’t support that you can add multiple keys. That’s why its not working.

    So as per suggestion of Eugene Astafiev you can use keyboard hook can solve your issue.

    Regards

    Deepak



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 14, 2016 3:27 AM
    Moderator
  • Thank you Eugene Astafiev

    I will try it.

    Best regards

    Johnny

    Thursday, April 14, 2016 8:52 AM
  • Hi Deepak Panchal10

    Thank you for your clarifying the issue.  

    Best regards

    Johnny

    Thursday, April 14, 2016 8:53 AM