Make Shortcuts functional for Excel Add-ins even when the task panel is not active

35 Views Asked by At

I am trying to add shortcuts to my Excel Add-in to be used in Office 365 as well. I notice that the shortcuts work only when I have clicked inside the Task pane and the Task panel is active. As soon as I get the focus out of the task pane, the shortcuts stop working. I have implemented the below JavaScript code so that when an Excel cell is active and shortcut keys are clicked, they should be functional.

var excelCell = document.getElementById('excelCell');
excelCell.addEventListener('keydown', function(event) {
    if (event.key === 'YourDesiredKey' && event.ctrlKey) {        
        event.preventDefault();
    }
});

When writing VBA Add-ins, shortcuts work irrespective of whether the custom Ribbon is active or not.

Can you please suggest modifications to the JavaScript code for achieving this?

1

There are 1 best solutions below

0
Kashif On

You have written code in keydown event of some DOM element which will be only triggered when that element is active and this behavior is controlled by browser not excel.

To have shortcut keys for excel, you should add shortcut key following this MS article.